merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / doctok / WW8ResourceModelImpl.cxx
blobdfc13a973549ed990e71b22a70706ceea02d273c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8ResourceModelImpl.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <WW8ResourceModelImpl.hxx>
32 #include <resources.hxx>
33 #include <util.hxx>
34 #include <WW8OutputWithDepth.hxx>
35 #include <resourcemodel/TableManager.hxx>
36 #include <rtl/string.hxx>
37 #include <resourcemodel/QNameToString.hxx>
39 namespace writerfilter {
41 namespace doctok
43 using namespace ::std;
46 // ------- WW8TableDataHandler ---------
48 typedef WW8PropertySet::Pointer_t TablePropsPointer_t;
50 class WW8TableDataHandler : public TableDataHandler<string,
51 TablePropsPointer_t>
53 public:
54 typedef boost::shared_ptr<WW8TableDataHandler> Pointer_t;
55 virtual void startTable(unsigned int nRows, unsigned int nDepth,
56 TablePropsPointer_t pProps);
57 virtual void endTable();
58 virtual void startRow(unsigned int nCols,
59 TablePropsPointer_t pProps);
60 virtual void endRow();
61 virtual void startCell(const string & start, TablePropsPointer_t pProps);
62 virtual void endCell(const string & end);
65 void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
66 TablePropsPointer_t /*pProps*/)
68 char sBuffer[256];
70 string tmpStr = "<tabledata.table rows=\"";
71 snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
72 tmpStr += sBuffer;
73 tmpStr += "\" depth=\"";
74 snprintf(sBuffer, sizeof(sBuffer), "%d", nDepth);
75 tmpStr += sBuffer;
76 tmpStr += "\">";
78 output.addItem(tmpStr);
81 void WW8TableDataHandler::endTable()
83 output.addItem("</tabledata.table>");
86 void WW8TableDataHandler::startRow
87 (unsigned int nCols, TablePropsPointer_t /*pProps*/)
89 char sBuffer[256];
91 snprintf(sBuffer, sizeof(sBuffer), "%d", nCols);
92 string tmpStr = "<tabledata.row cells=\"";
93 tmpStr += sBuffer;
94 tmpStr += "\">";
95 output.addItem(tmpStr);
98 void WW8TableDataHandler::endRow()
100 output.addItem("</tabledata.row>");
103 void WW8TableDataHandler::startCell(const string & start,
104 TablePropsPointer_t /*pProps*/)
106 output.addItem("<tabledata.cell>");
107 output.addItem(start);
108 output.addItem(", ");
111 void WW8TableDataHandler::endCell(const string & end)
113 output.addItem(end);
114 output.addItem("</tabledata.cell>");
117 // ----- WW8TableDataManager -------------------------------
119 class WW8TableManager :
120 public TableManager<string, TablePropsPointer_t>
122 typedef TableDataHandler<string, TablePropsPointer_t>
123 TableDataHandlerPointer_t;
125 public:
126 WW8TableManager();
127 virtual ~WW8TableManager() {}
128 virtual void endParagraphGroup();
129 virtual bool sprm(Sprm & rSprm);
132 WW8TableManager::WW8TableManager()
134 TableDataHandler<string, TablePropsPointer_t>::Pointer_t pHandler(new WW8TableDataHandler());
135 setHandler(pHandler);
138 bool WW8TableManager::sprm(Sprm & rSprm)
140 TableManager<string, TablePropsPointer_t>::sprm(rSprm);
141 output.setDepth(getTableDepthNew());
142 return true;
145 void WW8TableManager::endParagraphGroup()
147 string tmpStr = "<tabledepth depth=\"";
148 char sBuffer[256];
149 snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIdINT32, getTableDepthNew());
150 tmpStr += sBuffer;
151 tmpStr += "\"/>";
152 output.addItem(tmpStr);
153 TableManager<string, TablePropsPointer_t>::endParagraphGroup();
156 WW8TableManager gTableManager;
159 //-------- WW8TableReference -----------------------------------
161 void WW8TableReference::resolve(Table & /*rHandler*/)
163 output.addItem("<table/>");
166 string WW8TableReference::getType() const
168 return "WW8TableReference";
171 void WW8PropertiesReference::resolve(Properties & rHandler)
173 if (mpPropSet != NULL)
175 //mpPropSet->dump(clog);
177 if (mpPropSet->isPap())
179 WW8IntValue aValue(mpPropSet->get_istd());
181 rHandler.attribute(NS_rtf::LN_ISTD, aValue);
184 WW8PropertySetIterator::Pointer_t pIt = mpPropSet->begin();
185 WW8PropertySetIterator::Pointer_t pItEnd = mpPropSet->end();
189 while (! pIt->equal(*pItEnd))
191 WW8Sprm aSprm(pIt->get());
192 rHandler.sprm(aSprm);
194 ++(*pIt);
197 catch (ExceptionOutOfBounds e)
203 string WW8PropertiesReference::getType() const
205 return "WW8PropertiesReference";
208 WW8BinaryObjReference::WW8BinaryObjReference
209 (WW8StructBase & rParent, sal_uInt32 nOffset, sal_uInt32 nCount)
210 : WW8StructBase(rParent, nOffset, nCount)
214 WW8BinaryObjReference::WW8BinaryObjReference
215 (WW8StructBase * pParent, sal_uInt32 nOffset, sal_uInt32 nCount)
216 : WW8StructBase(pParent, nOffset, nCount)
220 WW8BinaryObjReference::WW8BinaryObjReference
221 (WW8StructBase * pParent)
222 : WW8StructBase(pParent, 0x0, pParent->getCount())
226 WW8BinaryObjReference::WW8BinaryObjReference
227 (WW8Stream & rStream, sal_uInt32 nOffset, sal_uInt32 nCount)
228 : WW8StructBase(rStream, nOffset, nCount)
232 writerfilter::Reference<BinaryObj>::Pointer_t
233 WW8BinaryObjReference::getBinary()
235 return writerfilter::Reference<BinaryObj>::Pointer_t
236 (new WW8BinaryObjReference(*this));
239 void WW8BinaryObjReference::resolve(BinaryObj & rHandler)
241 writerfilter::Reference<Properties>::Pointer_t pRef =
242 writerfilter::Reference<Properties>::Pointer_t();
244 if (getCount() > 0)
245 rHandler.data(get(0), getCount(), pRef);
248 string WW8BinaryObjReference::getType() const
250 return "WW8BinaryObjReference";
253 sal_uInt32 WW8Sprm::getId() const
255 sal_uInt32 nResult = 0;
257 if (mpProperty.get() != NULL)
258 nResult = mpProperty->getId();
259 else if (mpBinary.get() != NULL)
260 nResult = NS_rtf::LN_blob;
262 return nResult;
265 string WW8Sprm::toString() const
267 string sResult = "";
269 if (mpProperty.get() != NULL)
270 sResult = mpProperty->toString();
272 return sResult;
275 Value::Pointer_t WW8Sprm::getValue()
277 Value::Pointer_t pResult;
279 if (mpProperty.get() != NULL)
280 pResult = Value::Pointer_t(createValue(mpProperty->getParam()));
282 return pResult;
285 writerfilter::Reference<BinaryObj>::Pointer_t WW8Sprm::getBinary()
287 writerfilter::Reference<BinaryObj>::Pointer_t pResult;
289 if (mpBinary.get() != NULL)
290 pResult = writerfilter::Reference<BinaryObj>::Pointer_t
291 (mpBinary->clone());
292 else if (mpProperty.get() != NULL)
293 pResult = createSprmBinary
294 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
296 return pResult;
299 writerfilter::Reference<Stream>::Pointer_t WW8Sprm::getStream()
301 return writerfilter::Reference<Stream>::Pointer_t();
304 writerfilter::Reference<Properties>::Pointer_t WW8Sprm::getProps()
306 writerfilter::Reference<Properties>::Pointer_t pResult;
308 if (mpProperty.get() != NULL)
310 pResult = createSprmProps
311 (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
314 return pResult;
317 Sprm::Kind WW8Sprm::getKind()
319 return SprmKind(getId());
322 string WW8Sprm::getName() const
324 return (*SprmIdToString::Instance())(getId());
327 int WW8Value::getInt() const
329 return 0;
332 uno::Any WW8Value::getAny() const
334 return uno::Any();
337 ::rtl::OUString WW8Value::getString() const
339 return ::rtl::OUString();
342 string WW8Value::toString() const
344 return string();
347 writerfilter::Reference<Properties>::Pointer_t WW8Value::getProperties()
349 return writerfilter::Reference<Properties>::Pointer_t();
352 writerfilter::Reference<Stream>::Pointer_t WW8Value::getStream()
354 return writerfilter::Reference<Stream>::Pointer_t();
357 writerfilter::Reference<BinaryObj>::Pointer_t WW8Value::getBinary()
359 return writerfilter::Reference<BinaryObj>::Pointer_t();
362 int WW8IntValue::getInt() const
364 return mValue;
367 ::rtl::OUString WW8IntValue::getString() const
369 return ::rtl::OUString::valueOf(static_cast<sal_Int32>(mValue));
372 uno::Any WW8IntValue::getAny() const
374 uno::Any aResult;
376 aResult <<= static_cast<sal_uInt32>(mValue);
378 return aResult;
381 string WW8IntValue::toString() const
383 char sBuffer[255];
385 snprintf(sBuffer, sizeof(sBuffer), "%x", mValue);
387 return string(sBuffer);
390 WW8Value::Pointer_t createValue(int value)
392 return WW8Value::Pointer_t(new WW8IntValue(value));
395 WW8Value::Pointer_t createValue(WW8Value::Pointer_t value)
397 return value;
400 int WW8StringValue::getInt() const
402 return 0;
405 ::rtl::OUString WW8StringValue::getString() const
407 return mString;
410 uno::Any WW8StringValue::getAny() const
412 uno::Any aResult;
414 aResult <<= mString;
416 return aResult;
419 string WW8StringValue::toString() const
421 string result;
423 sal_uInt32 nCount = mString.getLength();
424 for (sal_uInt32 n = 0; n < nCount; ++n)
426 if (mString[n] <= 0xff && isprint(mString[n]))
428 sal_Unicode nC = mString[n];
430 if (nC < 256)
431 result += sal::static_int_cast<char>(nC);
432 else
433 result += ".";
435 else
437 char sBuffer[64];
439 snprintf(sBuffer, sizeof(sBuffer), "\\u%04x", mString[n]);
440 result += sBuffer;
444 return result;
447 WW8Value::Pointer_t createValue(const rtl::OUString & rStr)
449 return WW8Value::Pointer_t(new WW8StringValue(rStr));
452 writerfilter::Reference<Properties>::Pointer_t
453 WW8PropertiesValue::getProperties()
455 return mRef;
458 string WW8PropertiesValue::toString() const
460 return "properties";
463 writerfilter::Reference<Stream>::Pointer_t WW8StreamValue::getStream()
465 return mRef;
468 string WW8StreamValue::toString() const
470 return "stream";
473 writerfilter::Reference<BinaryObj>::Pointer_t WW8BinaryObjValue::getBinary()
475 return mRef;
478 string WW8BinaryObjValue::toString() const
480 return "binaryObj";
483 WW8Value::Pointer_t createValue
484 (writerfilter::Reference<Properties>::Pointer_t rRef)
486 return WW8Value::Pointer_t(new WW8PropertiesValue(rRef));
489 WW8Value::Pointer_t createValue(writerfilter::Reference<Stream>::Pointer_t rRef)
491 return WW8Value::Pointer_t(new WW8StreamValue(rRef));
494 WW8Value::Pointer_t createValue
495 (writerfilter::Reference<BinaryObj>::Pointer_t rRef)
497 return WW8Value::Pointer_t(new WW8BinaryObjValue(rRef));