Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / WW8ResourceModelImpl.cxx
blobc77b68249492d6a6e21a12e9c37b20691841d3ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 namespace writerfilter {
29 namespace doctok
31 using namespace ::std;
34 // ------- WW8TableDataHandler ---------
36 typedef WW8PropertySet::Pointer_t TablePropsPointer_t;
38 class WW8TableDataHandler : public TableDataHandler<string,
39 TablePropsPointer_t>
41 public:
42 virtual ~WW8TableDataHandler() {}
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);
55 void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
56 TablePropsPointer_t /*pProps*/)
58 char sBuffer[256];
60 string tmpStr = "<tabledata.table rows=\"";
61 snprintf(sBuffer, sizeof(sBuffer), "%u", nRows);
62 tmpStr += sBuffer;
63 tmpStr += "\" depth=\"";
64 snprintf(sBuffer, sizeof(sBuffer), "%u", nDepth);
65 tmpStr += sBuffer;
66 tmpStr += "\">";
68 output.addItem(tmpStr);
71 void WW8TableDataHandler::endTable(unsigned int /*nestedTableLevel*/)
73 output.addItem("</tabledata.table>");
76 void WW8TableDataHandler::startRow
77 (unsigned int nCols, TablePropsPointer_t /*pProps*/)
79 char sBuffer[256];
81 snprintf(sBuffer, sizeof(sBuffer), "%u", nCols);
82 string tmpStr = "<tabledata.row cells=\"";
83 tmpStr += sBuffer;
84 tmpStr += "\">";
85 output.addItem(tmpStr);
88 void WW8TableDataHandler::endRow()
90 output.addItem("</tabledata.row>");
93 void WW8TableDataHandler::startCell(const string & start,
94 TablePropsPointer_t /*pProps*/)
96 output.addItem("<tabledata.cell>");
97 output.addItem(start);
98 output.addItem(", ");
101 void WW8TableDataHandler::endCell(const string & end)
103 output.addItem(end);
104 output.addItem("</tabledata.cell>");
107 //-------- WW8TableReference -----------------------------------
109 void WW8TableReference::resolve(Table & /*rHandler*/)
111 output.addItem("<table/>");
114 string WW8TableReference::getType() const
116 return "WW8TableReference";
119 void WW8PropertiesReference::resolve(Properties & rHandler)
121 if (mpPropSet != NULL)
123 if (mpPropSet->isPap())
125 WW8IntValue aValue(mpPropSet->get_istd());
127 rHandler.attribute(NS_rtf::LN_ISTD, aValue);
130 WW8PropertySetIterator::Pointer_t pIt = mpPropSet->begin();
131 WW8PropertySetIterator::Pointer_t pItEnd = mpPropSet->end();
135 while (! pIt->equal(*pItEnd))
137 WW8Sprm aSprm(pIt->get());
138 rHandler.sprm(aSprm);
140 ++(*pIt);
143 catch (ExceptionOutOfBounds)
149 string WW8PropertiesReference::getType() const
151 return "WW8PropertiesReference";
154 WW8BinaryObjReference::WW8BinaryObjReference
155 (WW8StructBase * pParent, sal_uInt32 nOffset, sal_uInt32 nCount)
156 : WW8StructBase(pParent, nOffset, nCount)
160 WW8BinaryObjReference::WW8BinaryObjReference
161 (WW8StructBase * pParent)
162 : WW8StructBase(pParent, 0x0, pParent->getCount())
166 writerfilter::Reference<BinaryObj>::Pointer_t
167 WW8BinaryObjReference::getBinary()
169 return writerfilter::Reference<BinaryObj>::Pointer_t
170 (new WW8BinaryObjReference(*this));
173 void WW8BinaryObjReference::resolve(BinaryObj & rHandler)
175 writerfilter::Reference<Properties>::Pointer_t pRef =
176 writerfilter::Reference<Properties>::Pointer_t();
178 if (getCount() > 0)
179 rHandler.data(get(0), getCount(), pRef);
182 string WW8BinaryObjReference::getType() const
184 return "WW8BinaryObjReference";
187 sal_uInt32 WW8Sprm::getId() const
189 sal_uInt32 nResult = 0;
191 if (mpProperty.get() != NULL)
192 nResult = mpProperty->getId();
193 else if (mpBinary.get() != NULL)
194 nResult = NS_rtf::LN_blob;
196 return nResult;
199 string WW8Sprm::toString() const
201 string sResult = "";
203 if (mpProperty.get() != NULL)
204 sResult = mpProperty->toString();
206 return sResult;
209 Value::Pointer_t WW8Sprm::getValue()
211 Value::Pointer_t pResult;
213 if (mpProperty.get() != NULL)
214 pResult = Value::Pointer_t(createValue(mpProperty->getParam()));
216 return pResult;
219 writerfilter::Reference<BinaryObj>::Pointer_t WW8Sprm::getBinary()
221 writerfilter::Reference<BinaryObj>::Pointer_t pResult;
223 if (mpBinary.get() != NULL)
224 pResult = writerfilter::Reference<BinaryObj>::Pointer_t
225 (mpBinary->clone());
226 else if (mpProperty.get() != NULL)
227 pResult = createSprmBinary
228 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
230 return pResult;
233 writerfilter::Reference<Stream>::Pointer_t WW8Sprm::getStream()
235 return writerfilter::Reference<Stream>::Pointer_t();
238 writerfilter::Reference<Properties>::Pointer_t WW8Sprm::getProps()
240 writerfilter::Reference<Properties>::Pointer_t pResult;
242 if (mpProperty.get() != NULL)
244 pResult = createSprmProps
245 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
248 return pResult;
251 Sprm::Kind WW8Sprm::getKind()
253 return SprmKind(getId());
256 string WW8Sprm::getName() const
258 return (*SprmIdToString::Instance())(getId());
261 int WW8Value::getInt() const
263 return 0;
266 uno::Any WW8Value::getAny() const
268 return uno::Any();
271 OUString WW8Value::getString() const
273 return OUString();
276 string WW8Value::toString() const
278 return string();
281 writerfilter::Reference<Properties>::Pointer_t WW8Value::getProperties()
283 return writerfilter::Reference<Properties>::Pointer_t();
286 writerfilter::Reference<Stream>::Pointer_t WW8Value::getStream()
288 return writerfilter::Reference<Stream>::Pointer_t();
291 writerfilter::Reference<BinaryObj>::Pointer_t WW8Value::getBinary()
293 return writerfilter::Reference<BinaryObj>::Pointer_t();
296 int WW8IntValue::getInt() const
298 return mValue;
301 OUString WW8IntValue::getString() const
303 return OUString::number(mValue);
306 uno::Any WW8IntValue::getAny() const
308 uno::Any aResult;
310 aResult <<= static_cast<sal_uInt32>(mValue);
312 return aResult;
315 string WW8IntValue::toString() const
317 char sBuffer[255];
319 snprintf(sBuffer, sizeof(sBuffer), "%x", mValue);
321 return string(sBuffer);
324 WW8Value::Pointer_t createValue(int value)
326 return WW8Value::Pointer_t(new WW8IntValue(value));
329 SAL_WNODEPRECATED_DECLARATIONS_PUSH
330 WW8Value::Pointer_t createValue(WW8Value::Pointer_t value)
332 return value;
334 SAL_WNODEPRECATED_DECLARATIONS_POP
336 int WW8StringValue::getInt() const
338 return 0;
341 OUString WW8StringValue::getString() const
343 return mString;
346 uno::Any WW8StringValue::getAny() const
348 uno::Any aResult;
350 aResult <<= mString;
352 return aResult;
355 string WW8StringValue::toString() const
357 string result;
359 sal_uInt32 nCount = mString.getLength();
360 for (sal_uInt32 n = 0; n < nCount; ++n)
362 if (mString[n] <= 0xff && isprint(mString[n]))
364 sal_Unicode nC = mString[n];
366 if (nC < 256)
367 result += sal::static_int_cast<char>(nC);
368 else
369 result += ".";
371 else
373 char sBuffer[64];
375 snprintf(sBuffer, sizeof(sBuffer), "\\u%04x", mString[n]);
376 result += sBuffer;
380 return result;
383 WW8Value::Pointer_t createValue(const OUString & rStr)
385 return WW8Value::Pointer_t(new WW8StringValue(rStr));
388 writerfilter::Reference<Properties>::Pointer_t
389 WW8PropertiesValue::getProperties()
391 return mRef;
394 string WW8PropertiesValue::toString() const
396 return "properties";
399 writerfilter::Reference<Stream>::Pointer_t WW8StreamValue::getStream()
401 return mRef;
404 string WW8StreamValue::toString() const
406 return "stream";
409 writerfilter::Reference<BinaryObj>::Pointer_t WW8BinaryObjValue::getBinary()
411 return mRef;
414 string WW8BinaryObjValue::toString() const
416 return "binaryObj";
419 WW8Value::Pointer_t createValue
420 (writerfilter::Reference<Properties>::Pointer_t rRef)
422 return WW8Value::Pointer_t(new WW8PropertiesValue(rRef));
425 WW8Value::Pointer_t createValue(writerfilter::Reference<Stream>::Pointer_t rRef)
427 return WW8Value::Pointer_t(new WW8StreamValue(rRef));
430 WW8Value::Pointer_t createValue
431 (writerfilter::Reference<BinaryObj>::Pointer_t rRef)
433 return WW8Value::Pointer_t(new WW8BinaryObjValue(rRef));
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */