merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / ooxml / OOXMLPropertySetImpl.cxx
blobd469fdc32bd8f71fccce8f85ad54033e51b6dca9
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: OOXMLPropertySetImpl.cxx,v $
10 * $Revision: 1.27 $
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 "OOXMLPropertySetImpl.hxx"
32 #include <stdio.h>
33 #include <iostream>
34 #include <resourcemodel/QNameToString.hxx>
35 #include <com/sun/star/drawing/XShape.hpp>
37 //#define DEBUG_RESOLVE
39 namespace writerfilter {
40 namespace ooxml
42 using namespace ::std;
44 static ::rtl::OUString strue(RTL_CONSTASCII_USTRINGPARAM("true"));
45 static ::rtl::OUString sTrue(RTL_CONSTASCII_USTRINGPARAM("True"));
46 static ::rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("1"));
47 static ::rtl::OUString sOn(RTL_CONSTASCII_USTRINGPARAM("On"));
48 static ::rtl::OUString son(RTL_CONSTASCII_USTRINGPARAM("on"));
50 OOXMLProperty::~OOXMLProperty()
54 OOXMLPropertySet::~OOXMLPropertySet()
58 OOXMLTable::~OOXMLTable()
62 OOXMLPropertyImpl::OOXMLPropertyImpl(Id id, OOXMLValue::Pointer_t pValue,
63 OOXMLPropertyImpl::Type_t eType)
64 : mId(id), mpValue(pValue), meType(eType)
68 OOXMLPropertyImpl::OOXMLPropertyImpl(const OOXMLPropertyImpl & rSprm)
69 : OOXMLProperty(), mId(rSprm.mId), mpValue(rSprm.mpValue), meType(rSprm.meType)
73 OOXMLPropertyImpl::~OOXMLPropertyImpl()
77 sal_uInt32 OOXMLPropertyImpl::getId() const
79 return mId;
82 Value::Pointer_t OOXMLPropertyImpl::getValue()
84 Value::Pointer_t pResult;
86 if (mpValue.get() != NULL)
87 pResult = Value::Pointer_t(mpValue->clone());
88 else
89 pResult = Value::Pointer_t(new OOXMLValue());
91 return pResult;
94 writerfilter::Reference<BinaryObj>::Pointer_t OOXMLPropertyImpl::getBinary()
96 writerfilter::Reference<BinaryObj>::Pointer_t pResult;
98 if (mpValue.get() != NULL)
99 pResult = mpValue->getBinary();
101 return pResult;
104 writerfilter::Reference<Stream>::Pointer_t OOXMLPropertyImpl::getStream()
106 writerfilter::Reference<Stream>::Pointer_t pResult;
108 if (mpValue.get() != NULL)
109 pResult = mpValue->getStream();
111 return pResult;
114 writerfilter::Reference<Properties>::Pointer_t OOXMLPropertyImpl::getProps()
116 writerfilter::Reference<Properties>::Pointer_t pResult;
118 if (mpValue.get() != NULL)
119 pResult = mpValue->getProperties();
121 return pResult;
124 string OOXMLPropertyImpl::getName() const
126 string sResult = (*QNameToString::Instance())(mId);
128 if (sResult.length() == 0)
129 sResult = (*SprmIdToString::Instance())(mId);
131 return sResult;
134 string OOXMLPropertyImpl::toString() const
136 string sResult = "(";
138 sResult += getName();
139 sResult += ", ";
140 if (mpValue.get() != NULL)
141 sResult += mpValue->toString();
142 else
143 sResult +="(null)";
144 sResult +=")";
146 return sResult;
149 Sprm::Kind OOXMLPropertyImpl::getKind()
151 return SprmKind(getId());
154 Sprm * OOXMLPropertyImpl::clone()
156 return new OOXMLPropertyImpl(*this);
159 void OOXMLPropertyImpl::resolve(writerfilter::Properties & rProperties)
161 switch (meType)
163 case SPRM:
164 if (mId != 0x0)
165 rProperties.sprm(*this);
166 break;
167 case ATTRIBUTE:
168 rProperties.attribute(mId, *getValue());
169 break;
174 class OOXMLValue
177 OOXMLValue::OOXMLValue()
181 OOXMLValue::OOXMLValue(const rtl::OUString & /*rValue*/)
185 OOXMLValue::~OOXMLValue()
189 bool OOXMLValue::getBool() const
191 return false;
194 int OOXMLValue::getInt() const
196 return 0;
199 ::rtl::OUString OOXMLValue::getString() const
201 return ::rtl::OUString();
204 uno::Any OOXMLValue::getAny() const
206 return uno::Any();
209 writerfilter::Reference<Properties>::Pointer_t OOXMLValue::getProperties()
211 return writerfilter::Reference<Properties>::Pointer_t();
214 writerfilter::Reference<Stream>::Pointer_t OOXMLValue::getStream()
216 return writerfilter::Reference<Stream>::Pointer_t();
219 writerfilter::Reference<BinaryObj>::Pointer_t OOXMLValue::getBinary()
221 return writerfilter::Reference<BinaryObj>::Pointer_t();
224 string OOXMLValue::toString() const
226 return "OOXMLValue";
229 OOXMLValue * OOXMLValue::clone() const
231 return new OOXMLValue(*this);
235 class OOXMLBinaryValue
238 OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t
239 pBinaryObj)
240 : mpBinaryObj(pBinaryObj)
244 OOXMLBinaryValue::~OOXMLBinaryValue()
248 writerfilter::Reference<BinaryObj>::Pointer_t OOXMLBinaryValue::getBinary()
250 return mpBinaryObj;
253 string OOXMLBinaryValue::toString() const
255 return "BinaryObj";
258 OOXMLValue * OOXMLBinaryValue::clone() const
260 return new OOXMLBinaryValue(mpBinaryObj);
264 class OOXMLBooleanValue
267 OOXMLBooleanValue::OOXMLBooleanValue(bool bValue)
268 : mbValue(bValue)
272 OOXMLBooleanValue::OOXMLBooleanValue(const rtl::OUString & rValue)
273 : mbValue(false)
275 if (strue.compareTo(rValue) == 0
276 || sTrue.compareTo(rValue) == 0
277 || s1.compareTo(rValue) == 0
278 || son.compareTo(rValue) == 0
279 || sOn.compareTo(rValue) == 0)
280 mbValue = true;
281 else
282 mbValue = false;
285 OOXMLBooleanValue::~OOXMLBooleanValue()
289 bool OOXMLBooleanValue::getBool() const
291 return mbValue;
294 int OOXMLBooleanValue::getInt() const
296 return mbValue ? 1 : 0;
299 uno::Any OOXMLBooleanValue::getAny() const
301 uno::Any aResult(mbValue);
303 return aResult;
306 string OOXMLBooleanValue::toString() const
308 return mbValue ? "true" : "false";
311 OOXMLValue * OOXMLBooleanValue::clone() const
313 return new OOXMLBooleanValue(*this);
317 class OOXMLStringValue
320 OOXMLStringValue::OOXMLStringValue(const rtl::OUString & rStr)
321 : mStr(rStr)
325 OOXMLStringValue::~OOXMLStringValue()
329 uno::Any OOXMLStringValue::getAny() const
331 uno::Any aAny(mStr);
333 return aAny;
336 rtl::OUString OOXMLStringValue::getString() const
338 return mStr;
341 string OOXMLStringValue::toString() const
343 return OUStringToOString(mStr, RTL_TEXTENCODING_ASCII_US).getStr();
346 OOXMLValue * OOXMLStringValue::clone() const
348 return new OOXMLStringValue(*this);
352 class OOXMLInputStreamValue
354 OOXMLInputStreamValue::OOXMLInputStreamValue(uno::Reference<io::XInputStream> xInputStream)
355 : mxInputStream(xInputStream)
359 OOXMLInputStreamValue::~OOXMLInputStreamValue()
363 uno::Any OOXMLInputStreamValue::getAny() const
365 uno::Any aAny(mxInputStream);
367 return aAny;
370 string OOXMLInputStreamValue::toString() const
372 return "InputStream";
375 OOXMLValue * OOXMLInputStreamValue::clone() const
377 return new OOXMLInputStreamValue(mxInputStream);
381 struct OOXMLPropertySetImplCompare
384 bool OOXMLPropertySetImplCompare::operator()(const OOXMLProperty::Pointer_t x,
385 const OOXMLProperty::Pointer_t y) const
387 bool bResult = false;
389 if (x.get() == NULL && y.get() != NULL)
390 bResult = true;
391 else if (x.get() != NULL && y.get() != NULL)
392 bResult = x->getId() < y->getId();
394 return bResult;
398 class OOXMLPropertySetImpl
401 OOXMLPropertySetImpl::OOXMLPropertySetImpl()
402 : msType("OOXMLPropertySetImpl")
406 OOXMLPropertySetImpl::~OOXMLPropertySetImpl()
410 void OOXMLPropertySetImpl::resolve(Properties & rHandler)
412 OOXMLProperties_t::iterator aIt = begin();
413 while (aIt != end())
415 OOXMLProperty::Pointer_t pProp = *aIt;
417 if (pProp.get() != NULL)
418 pProp->resolve(rHandler);
419 #ifdef DEBUG_RESOLVE
420 else
422 debug_logger->startElement("error");
423 debug_logger->chars("zero-property");
424 debug_logger->endElement("error");
425 #endif
427 aIt++;
431 OOXMLPropertySetImpl::OOXMLProperties_t::iterator OOXMLPropertySetImpl::begin()
433 return mProperties.begin();
436 OOXMLPropertySetImpl::OOXMLProperties_t::iterator OOXMLPropertySetImpl::end()
438 return mProperties.end();
441 OOXMLPropertySetImpl::OOXMLProperties_t::const_iterator
442 OOXMLPropertySetImpl::begin() const
444 return mProperties.begin();
447 OOXMLPropertySetImpl::OOXMLProperties_t::const_iterator
448 OOXMLPropertySetImpl::end() const
450 return mProperties.end();
453 string OOXMLPropertySetImpl::getType() const
455 return msType;
458 void OOXMLPropertySetImpl::add(OOXMLProperty::Pointer_t pProperty)
460 if (pProperty.get() != NULL && pProperty->getId() != 0x0)
461 mProperties.push_back(pProperty);
464 void OOXMLPropertySetImpl::add(OOXMLPropertySet::Pointer_t pPropertySet)
466 if (pPropertySet.get() != NULL)
468 OOXMLPropertySetImpl * pSet =
469 dynamic_cast<OOXMLPropertySetImpl *>(pPropertySet.get());
471 if (pSet != NULL)
473 mProperties.resize(mProperties.size() + pSet->mProperties.size());
474 for (OOXMLProperties_t::iterator aIt = pSet->mProperties.begin();
475 aIt != pSet->mProperties.end(); aIt++)
476 add(*aIt);
481 OOXMLPropertySet * OOXMLPropertySetImpl::clone() const
483 return new OOXMLPropertySetImpl(*this);
486 void OOXMLPropertySetImpl::setType(const string & rsType)
488 msType = rsType;
491 string OOXMLPropertySetImpl::toString()
493 string sResult = "[";
494 char sBuffer[256];
495 snprintf(sBuffer, sizeof(sBuffer), "%p", this);
496 sResult += sBuffer;
497 sResult += ":";
499 OOXMLProperties_t::iterator aItBegin = begin();
500 OOXMLProperties_t::iterator aItEnd = end();
502 for (OOXMLProperties_t::iterator aIt = aItBegin; aIt != aItEnd; aIt++)
504 if (aIt != aItBegin)
505 sResult += ", ";
507 if ((*aIt).get() != NULL)
508 sResult += (*aIt)->toString();
509 else
510 sResult += "0x0";
513 sResult += "]";
515 return sResult;
519 class OOXMLPropertySetValue
522 OOXMLPropertySetValue::OOXMLPropertySetValue
523 (OOXMLPropertySet::Pointer_t pPropertySet)
524 : mpPropertySet(pPropertySet)
528 OOXMLPropertySetValue::~OOXMLPropertySetValue()
532 writerfilter::Reference<Properties>::Pointer_t OOXMLPropertySetValue::getProperties()
534 return writerfilter::Reference<Properties>::Pointer_t
535 (mpPropertySet->clone());
538 string OOXMLPropertySetValue::toString() const
540 char sBuffer[256];
542 snprintf(sBuffer, sizeof(sBuffer), "t:%p, m:%p", this, mpPropertySet.get());
544 return "OOXMLPropertySetValue(" + string(sBuffer) + ")";
547 OOXMLValue * OOXMLPropertySetValue::clone() const
549 return new OOXMLPropertySetValue(*this);
553 class OOXMLIntegerValue
556 OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue)
557 : mnValue(nValue)
561 OOXMLIntegerValue::OOXMLIntegerValue(const rtl::OUString & rValue)
562 : mnValue(0)
564 mnValue = rValue.toInt32();
567 OOXMLIntegerValue::~OOXMLIntegerValue()
571 int OOXMLIntegerValue::getInt() const
573 return mnValue;
576 uno::Any OOXMLIntegerValue::getAny() const
578 uno::Any aResult(mnValue);
580 return aResult;
583 OOXMLValue * OOXMLIntegerValue::clone() const
585 return new OOXMLIntegerValue(*this);
588 string OOXMLIntegerValue::toString() const
590 char buffer[256];
591 snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, mnValue);
593 return buffer;
597 class OOXMLHexValue
600 OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue)
601 : mnValue(nValue)
605 OOXMLHexValue::OOXMLHexValue(const rtl::OUString & rValue)
607 mnValue = static_cast<sal_uInt32>(rValue.toInt32(16));
610 OOXMLHexValue::~OOXMLHexValue()
614 int OOXMLHexValue::getInt() const
616 return mnValue;
619 OOXMLValue * OOXMLHexValue::clone() const
621 return new OOXMLHexValue(*this);
624 string OOXMLHexValue::toString() const
626 char buffer[256];
627 snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, mnValue);
629 return buffer;
633 class OOXMLListValue
635 OOXMLListValue::OOXMLListValue()
636 : OOXMLIntegerValue(0)
640 OOXMLListValue::OOXMLListValue(sal_Int32 nValue)
641 : OOXMLIntegerValue(nValue)
646 OOXMLListValue::~OOXMLListValue()
651 class OOXMLShapeValue
655 OOXMLShapeValue::OOXMLShapeValue(uno::Reference<XShape> rShape)
656 : mrShape(rShape)
660 OOXMLShapeValue::~OOXMLShapeValue()
664 uno::Any OOXMLShapeValue::getAny() const
666 return uno::Any(mrShape);
669 string OOXMLShapeValue::toString() const
671 return "Shape";
674 OOXMLValue * OOXMLShapeValue::clone() const
676 return new OOXMLShapeValue(mrShape);
680 class OOXMLTableImpl
683 OOXMLTableImpl::OOXMLTableImpl()
687 OOXMLTableImpl::~OOXMLTableImpl()
691 void OOXMLTableImpl::resolve(Table & rTable)
693 int nPos = 0;
695 PropertySets_t::iterator it = mPropertySets.begin();
696 PropertySets_t::iterator itEnd = mPropertySets.end();
698 while (it != itEnd)
700 writerfilter::Reference<Properties>::Pointer_t pProperties
701 ((*it)->getProperties());
703 if (pProperties.get() != NULL)
704 rTable.entry(nPos, pProperties);
706 ++nPos;
707 it++;
711 void OOXMLTableImpl::add(ValuePointer_t pPropertySet)
713 if (pPropertySet.get() != NULL)
714 mPropertySets.push_back(pPropertySet);
717 string OOXMLTableImpl::getType() const
719 return "OOXMLTableImpl";
722 OOXMLTable * OOXMLTableImpl::clone() const
724 return new OOXMLTableImpl(*this);
728 class: OOXMLPropertySetEntryToString
731 OOXMLPropertySetEntryToString::OOXMLPropertySetEntryToString(Id nId)
732 : mnId(nId)
736 OOXMLPropertySetEntryToString::~OOXMLPropertySetEntryToString()
740 void OOXMLPropertySetEntryToString::sprm(Sprm & /*rSprm*/)
744 void OOXMLPropertySetEntryToString::attribute(Id nId, Value & rValue)
746 if (nId == mnId)
747 mStr = rValue.getString();
750 const ::rtl::OUString & OOXMLPropertySetEntryToString::getString() const
752 return mStr;
755 OOXMLPropertySetEntryToInteger::OOXMLPropertySetEntryToInteger(Id nId)
756 : mnId(nId)
760 OOXMLPropertySetEntryToInteger::~OOXMLPropertySetEntryToInteger()
764 void OOXMLPropertySetEntryToInteger::sprm(Sprm & /*rSprm*/)
768 void OOXMLPropertySetEntryToInteger::attribute(Id nId, Value & rValue)
770 if (nId == mnId)
771 mnValue = rValue.getInt();
774 int OOXMLPropertySetEntryToInteger::getValue() const
776 return mnValue;