1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLPropertySetImpl.cxx,v $
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"
34 #include <resourcemodel/QNameToString.hxx>
35 #include <com/sun/star/drawing/XShape.hpp>
37 //#define DEBUG_RESOLVE
39 namespace writerfilter
{
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
82 Value::Pointer_t
OOXMLPropertyImpl::getValue()
84 Value::Pointer_t pResult
;
86 if (mpValue
.get() != NULL
)
87 pResult
= Value::Pointer_t(mpValue
->clone());
89 pResult
= Value::Pointer_t(new OOXMLValue());
94 writerfilter::Reference
<BinaryObj
>::Pointer_t
OOXMLPropertyImpl::getBinary()
96 writerfilter::Reference
<BinaryObj
>::Pointer_t pResult
;
98 if (mpValue
.get() != NULL
)
99 pResult
= mpValue
->getBinary();
104 writerfilter::Reference
<Stream
>::Pointer_t
OOXMLPropertyImpl::getStream()
106 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
108 if (mpValue
.get() != NULL
)
109 pResult
= mpValue
->getStream();
114 writerfilter::Reference
<Properties
>::Pointer_t
OOXMLPropertyImpl::getProps()
116 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
118 if (mpValue
.get() != NULL
)
119 pResult
= mpValue
->getProperties();
124 string
OOXMLPropertyImpl::getName() const
126 string sResult
= (*QNameToString::Instance())(mId
);
128 if (sResult
.length() == 0)
129 sResult
= (*SprmIdToString::Instance())(mId
);
134 string
OOXMLPropertyImpl::toString() const
136 string sResult
= "(";
138 sResult
+= getName();
140 if (mpValue
.get() != NULL
)
141 sResult
+= mpValue
->toString();
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
)
165 rProperties
.sprm(*this);
168 rProperties
.attribute(mId
, *getValue());
177 OOXMLValue::OOXMLValue()
181 OOXMLValue::OOXMLValue(const rtl::OUString
& /*rValue*/)
185 OOXMLValue::~OOXMLValue()
189 bool OOXMLValue::getBool() const
194 int OOXMLValue::getInt() const
199 ::rtl::OUString
OOXMLValue::getString() const
201 return ::rtl::OUString();
204 uno::Any
OOXMLValue::getAny() const
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
229 OOXMLValue
* OOXMLValue::clone() const
231 return new OOXMLValue(*this);
235 class OOXMLBinaryValue
238 OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t
240 : mpBinaryObj(pBinaryObj
)
244 OOXMLBinaryValue::~OOXMLBinaryValue()
248 writerfilter::Reference
<BinaryObj
>::Pointer_t
OOXMLBinaryValue::getBinary()
253 string
OOXMLBinaryValue::toString() const
258 OOXMLValue
* OOXMLBinaryValue::clone() const
260 return new OOXMLBinaryValue(mpBinaryObj
);
264 class OOXMLBooleanValue
267 OOXMLBooleanValue::OOXMLBooleanValue(bool bValue
)
272 OOXMLBooleanValue::OOXMLBooleanValue(const rtl::OUString
& rValue
)
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)
285 OOXMLBooleanValue::~OOXMLBooleanValue()
289 bool OOXMLBooleanValue::getBool() const
294 int OOXMLBooleanValue::getInt() const
296 return mbValue
? 1 : 0;
299 uno::Any
OOXMLBooleanValue::getAny() const
301 uno::Any
aResult(mbValue
);
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
)
325 OOXMLStringValue::~OOXMLStringValue()
329 uno::Any
OOXMLStringValue::getAny() const
336 rtl::OUString
OOXMLStringValue::getString() const
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
);
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
)
391 else if (x
.get() != NULL
&& y
.get() != NULL
)
392 bResult
= x
->getId() < y
->getId();
398 class OOXMLPropertySetImpl
401 OOXMLPropertySetImpl::OOXMLPropertySetImpl()
402 : msType("OOXMLPropertySetImpl")
406 OOXMLPropertySetImpl::~OOXMLPropertySetImpl()
410 void OOXMLPropertySetImpl::resolve(Properties
& rHandler
)
412 OOXMLProperties_t::iterator aIt
= begin();
415 OOXMLProperty::Pointer_t pProp
= *aIt
;
417 if (pProp
.get() != NULL
)
418 pProp
->resolve(rHandler
);
422 debug_logger
->startElement("error");
423 debug_logger
->chars("zero-property");
424 debug_logger
->endElement("error");
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
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());
473 mProperties
.resize(mProperties
.size() + pSet
->mProperties
.size());
474 for (OOXMLProperties_t::iterator aIt
= pSet
->mProperties
.begin();
475 aIt
!= pSet
->mProperties
.end(); aIt
++)
481 OOXMLPropertySet
* OOXMLPropertySetImpl::clone() const
483 return new OOXMLPropertySetImpl(*this);
486 void OOXMLPropertySetImpl::setType(const string
& rsType
)
491 string
OOXMLPropertySetImpl::toString()
493 string sResult
= "[";
495 snprintf(sBuffer
, sizeof(sBuffer
), "%p", this);
499 OOXMLProperties_t::iterator aItBegin
= begin();
500 OOXMLProperties_t::iterator aItEnd
= end();
502 for (OOXMLProperties_t::iterator aIt
= aItBegin
; aIt
!= aItEnd
; aIt
++)
507 if ((*aIt
).get() != NULL
)
508 sResult
+= (*aIt
)->toString();
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
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
)
561 OOXMLIntegerValue::OOXMLIntegerValue(const rtl::OUString
& rValue
)
564 mnValue
= rValue
.toInt32();
567 OOXMLIntegerValue::~OOXMLIntegerValue()
571 int OOXMLIntegerValue::getInt() const
576 uno::Any
OOXMLIntegerValue::getAny() const
578 uno::Any
aResult(mnValue
);
583 OOXMLValue
* OOXMLIntegerValue::clone() const
585 return new OOXMLIntegerValue(*this);
588 string
OOXMLIntegerValue::toString() const
591 snprintf(buffer
, sizeof(buffer
), "%" SAL_PRIdINT32
, mnValue
);
600 OOXMLHexValue::OOXMLHexValue(sal_uInt32 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
619 OOXMLValue
* OOXMLHexValue::clone() const
621 return new OOXMLHexValue(*this);
624 string
OOXMLHexValue::toString() const
627 snprintf(buffer
, sizeof(buffer
), "0x%" SAL_PRIxUINT32
, mnValue
);
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
)
660 OOXMLShapeValue::~OOXMLShapeValue()
664 uno::Any
OOXMLShapeValue::getAny() const
666 return uno::Any(mrShape
);
669 string
OOXMLShapeValue::toString() const
674 OOXMLValue
* OOXMLShapeValue::clone() const
676 return new OOXMLShapeValue(mrShape
);
683 OOXMLTableImpl::OOXMLTableImpl()
687 OOXMLTableImpl::~OOXMLTableImpl()
691 void OOXMLTableImpl::resolve(Table
& rTable
)
695 PropertySets_t::iterator it
= mPropertySets
.begin();
696 PropertySets_t::iterator itEnd
= mPropertySets
.end();
700 writerfilter::Reference
<Properties
>::Pointer_t pProperties
701 ((*it
)->getProperties());
703 if (pProperties
.get() != NULL
)
704 rTable
.entry(nPos
, pProperties
);
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
)
736 OOXMLPropertySetEntryToString::~OOXMLPropertySetEntryToString()
740 void OOXMLPropertySetEntryToString::sprm(Sprm
& /*rSprm*/)
744 void OOXMLPropertySetEntryToString::attribute(Id nId
, Value
& rValue
)
747 mStr
= rValue
.getString();
750 const ::rtl::OUString
& OOXMLPropertySetEntryToString::getString() const
755 OOXMLPropertySetEntryToInteger::OOXMLPropertySetEntryToInteger(Id nId
)
760 OOXMLPropertySetEntryToInteger::~OOXMLPropertySetEntryToInteger()
764 void OOXMLPropertySetEntryToInteger::sprm(Sprm
& /*rSprm*/)
768 void OOXMLPropertySetEntryToInteger::attribute(Id nId
, Value
& rValue
)
771 mnValue
= rValue
.getInt();
774 int OOXMLPropertySetEntryToInteger::getValue() const