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 <WW8ResourceModelImpl.hxx>
25 #include <resources.hxx>
26 #include <WW8OutputWithDepth.hxx>
27 #include <resourcemodel/TableManager.hxx>
28 #include <rtl/string.hxx>
29 #include <resourcemodel/QNameToString.hxx>
30
31 namespace writerfilter {
32
33 namespace doctok
34 {
35 using namespace ::std;
36
37
38 // ------- WW8TableDataHandler ---------
39
40 typedef WW8PropertySet::Pointer_t TablePropsPointer_t;
41
42 class WW8TableDataHandler : public TableDataHandler<string,
43 TablePropsPointer_t>
44 {
45 public:
46 typedef boost::shared_ptr<WW8TableDataHandler> Pointer_t;
47 virtual void startTable(
48 unsigned int nRows,
49 unsigned int nDepth,
50 TablePropsPointer_t pProps );
51 virtual void endTable(
52 const unsigned int nDepth );
53 virtual void startRow(unsigned int nCols,
54 TablePropsPointer_t pProps);
55 virtual void endRow();
56 virtual void startCell(const string & start, TablePropsPointer_t pProps);
57 virtual void endCell(const string & end);
58 };
59
startTable(unsigned int nRows,unsigned int nDepth,TablePropsPointer_t)60 void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
61 TablePropsPointer_t /*pProps*/)
62 {
63 char sBuffer[256];
64
65 string tmpStr = "<tabledata.table rows=\"";
66 snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
67 tmpStr += sBuffer;
68 tmpStr += "\" depth=\"";
69 snprintf(sBuffer, sizeof(sBuffer), "%d", nDepth);
70 tmpStr += sBuffer;
71 tmpStr += "\">";
72
73 output.addItem(tmpStr);
74 }
75
endTable(const unsigned int)76 void WW8TableDataHandler::endTable(
77 const unsigned int /*nTableDepth*/ )
78 {
79 output.addItem("</tabledata.table>");
80 }
81
startRow(unsigned int nCols,TablePropsPointer_t)82 void WW8TableDataHandler::startRow
83 (unsigned int nCols, TablePropsPointer_t /*pProps*/)
84 {
85 char sBuffer[256];
86
87 snprintf(sBuffer, sizeof(sBuffer), "%d", nCols);
88 string tmpStr = "<tabledata.row cells=\"";
89 tmpStr += sBuffer;
90 tmpStr += "\">";
91 output.addItem(tmpStr);
92 }
93
endRow()94 void WW8TableDataHandler::endRow()
95 {
96 output.addItem("</tabledata.row>");
97 }
98
startCell(const string & start,TablePropsPointer_t)99 void WW8TableDataHandler::startCell(const string & start,
100 TablePropsPointer_t /*pProps*/)
101 {
102 output.addItem("<tabledata.cell>");
103 output.addItem(start);
104 output.addItem(", ");
105 }
106
endCell(const string & end)107 void WW8TableDataHandler::endCell(const string & end)
108 {
109 output.addItem(end);
110 output.addItem("</tabledata.cell>");
111 }
112
113 // ----- WW8TableDataManager -------------------------------
114
115 class WW8TableManager :
116 public TableManager<string, TablePropsPointer_t>
117 {
118 typedef TableDataHandler<string, TablePropsPointer_t>
119 TableDataHandlerPointer_t;
120
121 public:
122 WW8TableManager();
~WW8TableManager()123 virtual ~WW8TableManager() {}
124 virtual void endParagraphGroup();
125 virtual bool sprm(Sprm & rSprm);
126 };
127
WW8TableManager()128 WW8TableManager::WW8TableManager()
129 {
130 TableDataHandler<string, TablePropsPointer_t>::Pointer_t pHandler(new WW8TableDataHandler());
131 setHandler(pHandler);
132 }
133
sprm(Sprm & rSprm)134 bool WW8TableManager::sprm(Sprm & rSprm)
135 {
136 TableManager<string, TablePropsPointer_t>::sprm(rSprm);
137 output.setDepth(getTableDepthNew());
138 return true;
139 }
140
endParagraphGroup()141 void WW8TableManager::endParagraphGroup()
142 {
143 string tmpStr = "<tabledepth depth=\"";
144 char sBuffer[256];
145 snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIdINT32, getTableDepthNew());
146 tmpStr += sBuffer;
147 tmpStr += "\"/>";
148 output.addItem(tmpStr);
149 TableManager<string, TablePropsPointer_t>::endParagraphGroup();
150 }
151
152 WW8TableManager gTableManager;
153
154
155 //-------- WW8TableReference -----------------------------------
156
resolve(Table &)157 void WW8TableReference::resolve(Table & /*rHandler*/)
158 {
159 output.addItem("<table/>");
160 }
161
getType() const162 string WW8TableReference::getType() const
163 {
164 return "WW8TableReference";
165 }
166
resolve(Properties & rHandler)167 void WW8PropertiesReference::resolve(Properties & rHandler)
168 {
169 if( bool(mpPropSet))
170 {
171 //mpPropSet->dump(clog);
172
173 if (mpPropSet->isPap())
174 {
175 WW8IntValue aValue(mpPropSet->get_istd());
176
177 rHandler.attribute(NS_rtf::LN_ISTD, aValue);
178 }
179
180 WW8PropertySetIterator::Pointer_t pIt = mpPropSet->begin();
181 WW8PropertySetIterator::Pointer_t pItEnd = mpPropSet->end();
182
183 try
184 {
185 while (! pIt->equal(*pItEnd))
186 {
187 WW8Sprm aSprm(pIt->get());
188 rHandler.sprm(aSprm);
189
190 ++(*pIt);
191 }
192 }
193 catch (ExceptionOutOfBounds e)
194 {
195 }
196 }
197 }
198
getType() const199 string WW8PropertiesReference::getType() const
200 {
201 return "WW8PropertiesReference";
202 }
203
WW8BinaryObjReference(WW8StructBase & rParent,sal_uInt32 nOffset,sal_uInt32 nCount)204 WW8BinaryObjReference::WW8BinaryObjReference
205 (WW8StructBase & rParent, sal_uInt32 nOffset, sal_uInt32 nCount)
206 : WW8StructBase(rParent, nOffset, nCount)
207 {
208 }
209
WW8BinaryObjReference(WW8StructBase * pParent,sal_uInt32 nOffset,sal_uInt32 nCount)210 WW8BinaryObjReference::WW8BinaryObjReference
211 (WW8StructBase * pParent, sal_uInt32 nOffset, sal_uInt32 nCount)
212 : WW8StructBase(pParent, nOffset, nCount)
213 {
214 }
215
WW8BinaryObjReference(WW8StructBase * pParent)216 WW8BinaryObjReference::WW8BinaryObjReference
217 (WW8StructBase * pParent)
218 : WW8StructBase(pParent, 0x0, pParent->getCount())
219 {
220 }
221
WW8BinaryObjReference(WW8Stream & rStream,sal_uInt32 nOffset,sal_uInt32 nCount)222 WW8BinaryObjReference::WW8BinaryObjReference
223 (WW8Stream & rStream, sal_uInt32 nOffset, sal_uInt32 nCount)
224 : WW8StructBase(rStream, nOffset, nCount)
225 {
226 }
227
228 writerfilter::Reference<BinaryObj>::Pointer_t
getBinary()229 WW8BinaryObjReference::getBinary()
230 {
231 return writerfilter::Reference<BinaryObj>::Pointer_t
232 (new WW8BinaryObjReference(*this));
233 }
234
resolve(BinaryObj & rHandler)235 void WW8BinaryObjReference::resolve(BinaryObj & rHandler)
236 {
237 writerfilter::Reference<Properties>::Pointer_t pRef =
238 writerfilter::Reference<Properties>::Pointer_t();
239
240 if (getCount() > 0)
241 rHandler.data(get(0), getCount(), pRef);
242 }
243
getType() const244 string WW8BinaryObjReference::getType() const
245 {
246 return "WW8BinaryObjReference";
247 }
248
getId() const249 sal_uInt32 WW8Sprm::getId() const
250 {
251 sal_uInt32 nResult = 0;
252
253 if (mpProperty.get() != NULL)
254 nResult = mpProperty->getId();
255 else if (mpBinary.get() != NULL)
256 nResult = NS_rtf::LN_blob;
257
258 return nResult;
259 }
260
toString() const261 string WW8Sprm::toString() const
262 {
263 string sResult = "";
264
265 if (mpProperty.get() != NULL)
266 sResult = mpProperty->toString();
267
268 return sResult;
269 }
270
getValue()271 Value::Pointer_t WW8Sprm::getValue()
272 {
273 Value::Pointer_t pResult;
274
275 if (mpProperty.get() != NULL)
276 pResult = Value::Pointer_t(createValue(mpProperty->getParam()));
277
278 return pResult;
279 }
280
getBinary()281 writerfilter::Reference<BinaryObj>::Pointer_t WW8Sprm::getBinary()
282 {
283 writerfilter::Reference<BinaryObj>::Pointer_t pResult;
284
285 if (mpBinary.get() != NULL)
286 pResult = writerfilter::Reference<BinaryObj>::Pointer_t
287 (mpBinary->clone());
288 else if (mpProperty.get() != NULL)
289 pResult = createSprmBinary
290 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
291
292 return pResult;
293 }
294
getStream()295 writerfilter::Reference<Stream>::Pointer_t WW8Sprm::getStream()
296 {
297 return writerfilter::Reference<Stream>::Pointer_t();
298 }
299
getProps()300 writerfilter::Reference<Properties>::Pointer_t WW8Sprm::getProps()
301 {
302 writerfilter::Reference<Properties>::Pointer_t pResult;
303
304 if (mpProperty.get() != NULL)
305 {
306 pResult = createSprmProps
307 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
308 }
309
310 return pResult;
311 }
312
getKind()313 Sprm::Kind WW8Sprm::getKind()
314 {
315 return SprmKind(getId());
316 }
317
getName() const318 string WW8Sprm::getName() const
319 {
320 return (*SprmIdToString::Instance())(getId());
321 }
322
getInt() const323 sal_Int32 WW8Value::getInt() const
324 {
325 return 0;
326 }
327
getAny() const328 uno::Any WW8Value::getAny() const
329 {
330 return uno::Any();
331 }
332
getString() const333 ::rtl::OUString WW8Value::getString() const
334 {
335 return ::rtl::OUString();
336 }
337
toString() const338 string WW8Value::toString() const
339 {
340 return string();
341 }
342
getProperties()343 writerfilter::Reference<Properties>::Pointer_t WW8Value::getProperties()
344 {
345 return writerfilter::Reference<Properties>::Pointer_t();
346 }
347
getStream()348 writerfilter::Reference<Stream>::Pointer_t WW8Value::getStream()
349 {
350 return writerfilter::Reference<Stream>::Pointer_t();
351 }
352
getBinary()353 writerfilter::Reference<BinaryObj>::Pointer_t WW8Value::getBinary()
354 {
355 return writerfilter::Reference<BinaryObj>::Pointer_t();
356 }
357
getInt() const358 sal_Int32 WW8IntValue::getInt() const
359 {
360 return mValue;
361 }
362
getString() const363 ::rtl::OUString WW8IntValue::getString() const
364 {
365 return ::rtl::OUString::valueOf(static_cast<sal_Int32>(mValue));
366 }
367
getAny() const368 uno::Any WW8IntValue::getAny() const
369 {
370 uno::Any aResult;
371
372 aResult <<= static_cast<sal_uInt32>(mValue);
373
374 return aResult;
375 }
376
toString() const377 string WW8IntValue::toString() const
378 {
379 char sBuffer[255];
380
381 snprintf(sBuffer, sizeof(sBuffer), "%x", mValue);
382
383 return string(sBuffer);
384 }
385
createValue(int value)386 WW8Value::Pointer_t createValue(int value)
387 {
388 return WW8Value::Pointer_t(new WW8IntValue(value));
389 }
390
createValue(WW8Value::Pointer_t value)391 WW8Value::Pointer_t createValue(WW8Value::Pointer_t value)
392 {
393 return value;
394 }
395
getInt() const396 sal_Int32 WW8StringValue::getInt() const
397 {
398 return 0;
399 }
400
getString() const401 ::rtl::OUString WW8StringValue::getString() const
402 {
403 return mString;
404 }
405
getAny() const406 uno::Any WW8StringValue::getAny() const
407 {
408 uno::Any aResult;
409
410 aResult <<= mString;
411
412 return aResult;
413 }
414
toString() const415 string WW8StringValue::toString() const
416 {
417 string result;
418
419 sal_uInt32 nCount = mString.getLength();
420 for (sal_uInt32 n = 0; n < nCount; ++n)
421 {
422 if (mString[n] <= 0xff && isprint(mString[n]))
423 {
424 sal_Unicode nC = mString[n];
425
426 if (nC < 256)
427 result += sal::static_int_cast<char>(nC);
428 else
429 result += ".";
430 }
431 else
432 {
433 char sBuffer[64];
434
435 snprintf(sBuffer, sizeof(sBuffer), "\\u%04x", mString[n]);
436 result += sBuffer;
437 }
438 }
439
440 return result;
441 }
442
createValue(const rtl::OUString & rStr)443 WW8Value::Pointer_t createValue(const rtl::OUString & rStr)
444 {
445 return WW8Value::Pointer_t(new WW8StringValue(rStr));
446 }
447
448 writerfilter::Reference<Properties>::Pointer_t
getProperties()449 WW8PropertiesValue::getProperties()
450 {
451 return mRef;
452 }
453
toString() const454 string WW8PropertiesValue::toString() const
455 {
456 return "properties";
457 }
458
getStream()459 writerfilter::Reference<Stream>::Pointer_t WW8StreamValue::getStream()
460 {
461 return mRef;
462 }
463
toString() const464 string WW8StreamValue::toString() const
465 {
466 return "stream";
467 }
468
getBinary()469 writerfilter::Reference<BinaryObj>::Pointer_t WW8BinaryObjValue::getBinary()
470 {
471 return mRef;
472 }
473
toString() const474 string WW8BinaryObjValue::toString() const
475 {
476 return "binaryObj";
477 }
478
createValue(writerfilter::Reference<Properties>::Pointer_t rRef)479 WW8Value::Pointer_t createValue
480 (writerfilter::Reference<Properties>::Pointer_t rRef)
481 {
482 return WW8Value::Pointer_t(new WW8PropertiesValue(rRef));
483 }
484
createValue(writerfilter::Reference<Stream>::Pointer_t rRef)485 WW8Value::Pointer_t createValue(writerfilter::Reference<Stream>::Pointer_t rRef)
486 {
487 return WW8Value::Pointer_t(new WW8StreamValue(rRef));
488 }
489
createValue(writerfilter::Reference<BinaryObj>::Pointer_t rRef)490 WW8Value::Pointer_t createValue
491 (writerfilter::Reference<BinaryObj>::Pointer_t rRef)
492 {
493 return WW8Value::Pointer_t(new WW8BinaryObjValue(rRef));
494 }
495
496
497 }
498
499 }
500
501