1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "OOXMLPropertySetImpl.hxx"
23 #include <ooxml/QNameToString.hxx>
24 #include <com/sun/star/drawing/XShape.hpp>
25 #include <oox/token/tokens.hxx>
27 namespace writerfilter
{
30 using namespace ::std
;
31 using namespace com::sun::star
;
33 OOXMLProperty::~OOXMLProperty()
37 OOXMLPropertySet::~OOXMLPropertySet()
41 OOXMLTable::~OOXMLTable()
45 OOXMLPropertyImpl::OOXMLPropertyImpl(Id id
, OOXMLValue::Pointer_t pValue
,
46 OOXMLPropertyImpl::Type_t eType
)
47 : mId(id
), mpValue(pValue
), meType(eType
)
51 OOXMLPropertyImpl::OOXMLPropertyImpl(const OOXMLPropertyImpl
& rSprm
)
52 : OOXMLProperty(), mId(rSprm
.mId
), mpValue(rSprm
.mpValue
), meType(rSprm
.meType
)
56 OOXMLPropertyImpl::~OOXMLPropertyImpl()
60 sal_uInt32
OOXMLPropertyImpl::getId() const
65 Value::Pointer_t
OOXMLPropertyImpl::getValue()
67 Value::Pointer_t pResult
;
69 if (mpValue
.get() != nullptr)
70 pResult
= Value::Pointer_t(mpValue
->clone());
72 pResult
= Value::Pointer_t(new OOXMLValue());
77 writerfilter::Reference
<BinaryObj
>::Pointer_t
OOXMLPropertyImpl::getBinary()
79 writerfilter::Reference
<BinaryObj
>::Pointer_t pResult
;
81 if (mpValue
.get() != nullptr)
82 pResult
= mpValue
->getBinary();
87 writerfilter::Reference
<Stream
>::Pointer_t
OOXMLPropertyImpl::getStream()
89 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
91 if (mpValue
.get() != nullptr)
92 pResult
= mpValue
->getStream();
97 writerfilter::Reference
<Properties
>::Pointer_t
OOXMLPropertyImpl::getProps()
99 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
101 if (mpValue
.get() != nullptr)
102 pResult
= mpValue
->getProperties();
107 #ifdef DEBUG_WRITERFILTER
108 string
OOXMLPropertyImpl::getName() const
112 sResult
= (*QNameToString::Instance())(mId
);
114 if (sResult
.length() == 0)
115 sResult
= fastTokenToId(mId
);
117 if (sResult
.length() == 0)
119 static char sBuffer
[256];
121 snprintf(sBuffer
, sizeof(sBuffer
), "%" SAL_PRIxUINT32
, mId
);
129 #ifdef DEBUG_WRITERFILTER
130 string
OOXMLPropertyImpl::toString() const
132 string sResult
= "(";
134 sResult
+= getName();
136 if (mpValue
.get() != nullptr)
137 sResult
+= mpValue
->toString();
146 Sprm
* OOXMLPropertyImpl::clone()
148 return new OOXMLPropertyImpl(*this);
151 void OOXMLPropertyImpl::resolve(writerfilter::Properties
& rProperties
)
153 writerfilter::Properties
* pProperties
= nullptr;
154 pProperties
= &rProperties
;
160 pProperties
->sprm(*this);
163 pProperties
->attribute(mId
, *getValue());
172 OOXMLValue::OOXMLValue()
176 OOXMLValue::~OOXMLValue()
180 bool OOXMLValue::getBool() const
185 int OOXMLValue::getInt() const
190 OUString
OOXMLValue::getString() const
195 uno::Any
OOXMLValue::getAny() const
200 writerfilter::Reference
<Properties
>::Pointer_t
OOXMLValue::getProperties()
202 return writerfilter::Reference
<Properties
>::Pointer_t();
205 writerfilter::Reference
<Stream
>::Pointer_t
OOXMLValue::getStream()
207 return writerfilter::Reference
<Stream
>::Pointer_t();
210 writerfilter::Reference
<BinaryObj
>::Pointer_t
OOXMLValue::getBinary()
212 return writerfilter::Reference
<BinaryObj
>::Pointer_t();
215 #ifdef DEBUG_WRITERFILTER
216 string
OOXMLValue::toString() const
222 OOXMLValue
* OOXMLValue::clone() const
224 return new OOXMLValue(*this);
228 class OOXMLBinaryValue
231 OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t
233 : mpBinaryObj(pBinaryObj
)
237 OOXMLBinaryValue::~OOXMLBinaryValue()
241 writerfilter::Reference
<BinaryObj
>::Pointer_t
OOXMLBinaryValue::getBinary()
246 #ifdef DEBUG_WRITERFILTER
247 string
OOXMLBinaryValue::toString() const
253 OOXMLValue
* OOXMLBinaryValue::clone() const
255 return new OOXMLBinaryValue(mpBinaryObj
);
259 class OOXMLBooleanValue
262 static bool GetBooleanValue(const char *pValue
)
264 return !strcmp(pValue
, "true")
265 || !strcmp(pValue
, "True")
266 || !strcmp(pValue
, "1")
267 || !strcmp(pValue
, "on")
268 || !strcmp(pValue
, "On");
271 OOXMLValue::Pointer_t
OOXMLBooleanValue::Create(bool bValue
)
273 static OOXMLValue::Pointer_t
False(new OOXMLBooleanValue (false));
274 static OOXMLValue::Pointer_t
True(new OOXMLBooleanValue (true));
276 return bValue
? True
: False
;
279 OOXMLValue::Pointer_t
OOXMLBooleanValue::Create(const char *pValue
)
281 return Create (GetBooleanValue(pValue
));
284 OOXMLBooleanValue::OOXMLBooleanValue(bool bValue
)
289 OOXMLBooleanValue::~OOXMLBooleanValue()
293 bool OOXMLBooleanValue::getBool() const
298 int OOXMLBooleanValue::getInt() const
300 return mbValue
? 1 : 0;
303 uno::Any
OOXMLBooleanValue::getAny() const
305 uno::Any
aResult(mbValue
);
310 #ifdef DEBUG_WRITERFILTER
311 string
OOXMLBooleanValue::toString() const
313 return mbValue
? "true" : "false";
317 OOXMLValue
* OOXMLBooleanValue::clone() const
319 return new OOXMLBooleanValue(*this);
323 class OOXMLStringValue
326 OOXMLStringValue::OOXMLStringValue(const OUString
& rStr
)
331 OOXMLStringValue::~OOXMLStringValue()
335 uno::Any
OOXMLStringValue::getAny() const
342 OUString
OOXMLStringValue::getString() const
347 #ifdef DEBUG_WRITERFILTER
348 string
OOXMLStringValue::toString() const
350 return OUStringToOString(mStr
, RTL_TEXTENCODING_ASCII_US
).getStr();
354 OOXMLValue
* OOXMLStringValue::clone() const
356 return new OOXMLStringValue(*this);
360 class OOXMLInputStreamValue
362 OOXMLInputStreamValue::OOXMLInputStreamValue(uno::Reference
<io::XInputStream
> xInputStream
)
363 : mxInputStream(xInputStream
)
367 OOXMLInputStreamValue::~OOXMLInputStreamValue()
371 uno::Any
OOXMLInputStreamValue::getAny() const
373 uno::Any
aAny(mxInputStream
);
378 #ifdef DEBUG_WRITERFILTER
379 string
OOXMLInputStreamValue::toString() const
381 return "InputStream";
385 OOXMLValue
* OOXMLInputStreamValue::clone() const
387 return new OOXMLInputStreamValue(mxInputStream
);
391 struct OOXMLPropertySetImplCompare
394 bool OOXMLPropertySetImplCompare::operator()(const OOXMLProperty::Pointer_t
& x
,
395 const OOXMLProperty::Pointer_t
& y
) const
397 bool bResult
= false;
399 if (x
.get() == nullptr && y
.get() != nullptr)
401 else if (x
.get() != nullptr && y
.get() != nullptr)
402 bResult
= x
->getId() < y
->getId();
408 class OOXMLPropertySetImpl
411 OOXMLPropertySetImpl::OOXMLPropertySetImpl()
413 static OString
aName("OOXMLPropertySetImpl");
417 OOXMLPropertySetImpl::~OOXMLPropertySetImpl()
421 void OOXMLPropertySetImpl::resolve(Properties
& rHandler
)
423 // The pProp->resolve(rHandler) call below can cause elements to
424 // be appended to mProperties. I don't think it can cause elements
425 // to be deleted. But let's check with < here just to be safe that
426 // the indexing below works.
427 for (size_t nIt
= 0; nIt
< mProperties
.size(); ++nIt
)
429 OOXMLProperty::Pointer_t pProp
= mProperties
[nIt
];
431 if (pProp
.get() != nullptr)
432 pProp
->resolve(rHandler
);
436 OOXMLPropertySetImpl::OOXMLProperties_t::iterator
OOXMLPropertySetImpl::begin()
438 return mProperties
.begin();
441 OOXMLPropertySetImpl::OOXMLProperties_t::iterator
OOXMLPropertySetImpl::end()
443 return mProperties
.end();
446 OOXMLPropertySetImpl::OOXMLProperties_t::const_iterator
447 OOXMLPropertySetImpl::begin() const
449 return mProperties
.begin();
452 OOXMLPropertySetImpl::OOXMLProperties_t::const_iterator
453 OOXMLPropertySetImpl::end() const
455 return mProperties
.end();
458 void OOXMLPropertySetImpl::add(OOXMLProperty::Pointer_t pProperty
)
460 if (pProperty
.get() != nullptr && pProperty
->getId() != 0x0)
462 mProperties
.push_back(pProperty
);
466 void OOXMLPropertySetImpl::add(OOXMLPropertySet::Pointer_t pPropertySet
)
468 if (pPropertySet
.get() != nullptr)
470 OOXMLPropertySetImpl
* pSet
=
471 dynamic_cast<OOXMLPropertySetImpl
*>(pPropertySet
.get());
475 mProperties
.resize(mProperties
.size() + pSet
->mProperties
.size());
476 for (OOXMLProperties_t::iterator aIt
= pSet
->mProperties
.begin();
477 aIt
!= pSet
->mProperties
.end(); ++aIt
)
483 OOXMLPropertySet
* OOXMLPropertySetImpl::clone() const
485 return new OOXMLPropertySetImpl(*this);
488 void OOXMLPropertySetImpl::setType(const string
& rsType
)
490 maType
= OString(rsType
.c_str(), rsType
.size());
493 #ifdef DEBUG_WRITERFILTER
494 string
OOXMLPropertySetImpl::toString()
496 string sResult
= "[";
498 snprintf(sBuffer
, sizeof(sBuffer
), "%p", this);
502 OOXMLProperties_t::iterator aItBegin
= begin();
503 OOXMLProperties_t::iterator aItEnd
= end();
505 for (OOXMLProperties_t::iterator aIt
= aItBegin
; aIt
!= aItEnd
; ++aIt
)
510 if ((*aIt
).get() != nullptr)
511 sResult
+= (*aIt
)->toString();
523 class OOXMLPropertySetValue
526 OOXMLPropertySetValue::OOXMLPropertySetValue
527 (OOXMLPropertySet::Pointer_t pPropertySet
)
528 : mpPropertySet(pPropertySet
)
532 OOXMLPropertySetValue::~OOXMLPropertySetValue()
536 writerfilter::Reference
<Properties
>::Pointer_t
OOXMLPropertySetValue::getProperties()
538 return writerfilter::Reference
<Properties
>::Pointer_t
539 (mpPropertySet
->clone());
542 #ifdef DEBUG_WRITERFILTER
543 string
OOXMLPropertySetValue::toString() const
547 snprintf(sBuffer
, sizeof(sBuffer
), "t:%p, m:%p", this, mpPropertySet
.get());
549 return "OOXMLPropertySetValue(" + string(sBuffer
) + ")";
553 OOXMLValue
* OOXMLPropertySetValue::clone() const
555 return new OOXMLPropertySetValue(*this);
559 class OOXMLIntegerValue
562 OOXMLValue::Pointer_t
OOXMLIntegerValue::Create(sal_Int32 nValue
)
564 static OOXMLValue::Pointer_t
Zero(new OOXMLIntegerValue (0));
565 static OOXMLValue::Pointer_t
One(new OOXMLIntegerValue (1));
566 static OOXMLValue::Pointer_t
Two(new OOXMLIntegerValue (2));
567 static OOXMLValue::Pointer_t
Three(new OOXMLIntegerValue (3));
568 static OOXMLValue::Pointer_t
Four(new OOXMLIntegerValue (4));
569 static OOXMLValue::Pointer_t
Five(new OOXMLIntegerValue (5));
570 static OOXMLValue::Pointer_t
Six(new OOXMLIntegerValue (6));
571 static OOXMLValue::Pointer_t
Seven(new OOXMLIntegerValue (7));
572 static OOXMLValue::Pointer_t
Eight(new OOXMLIntegerValue (8));
573 static OOXMLValue::Pointer_t
Nine(new OOXMLIntegerValue (9));
579 case 3: return Three
;
583 case 7: return Seven
;
584 case 8: return Eight
;
589 OOXMLValue::Pointer_t
value(new OOXMLIntegerValue(nValue
));
594 OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue
)
599 OOXMLIntegerValue::~OOXMLIntegerValue()
603 int OOXMLIntegerValue::getInt() const
608 uno::Any
OOXMLIntegerValue::getAny() const
610 uno::Any
aResult(mnValue
);
615 OOXMLValue
* OOXMLIntegerValue::clone() const
617 return new OOXMLIntegerValue(*this);
620 #ifdef DEBUG_WRITERFILTER
621 string
OOXMLIntegerValue::toString() const
624 snprintf(buffer
, sizeof(buffer
), "%" SAL_PRIdINT32
, mnValue
);
634 OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue
)
639 OOXMLHexValue::OOXMLHexValue(const char * pValue
)
641 mnValue
= rtl_str_toUInt32(pValue
, 16);
644 OOXMLHexValue::~OOXMLHexValue()
648 int OOXMLHexValue::getInt() const
653 OOXMLValue
* OOXMLHexValue::clone() const
655 return new OOXMLHexValue(*this);
658 #ifdef DEBUG_WRITERFILTER
659 string
OOXMLHexValue::toString() const
662 snprintf(buffer
, sizeof(buffer
), "0x%" SAL_PRIxUINT32
, mnValue
);
668 // OOXMLUniversalMeasureValue
670 OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const char * pValue
)
672 mnValue
= rtl_str_toUInt32(pValue
, 10); // will ignore the trailing 'pt'
674 int nLen
= strlen(pValue
);
676 pValue
[nLen
-2] == 'p' &&
677 pValue
[nLen
-1] == 't')
679 mnValue
= mnValue
* 20;
683 OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue()
687 int OOXMLUniversalMeasureValue::getInt() const
692 OOXMLValue
* OOXMLUniversalMeasureValue::clone() const
694 return new OOXMLUniversalMeasureValue(*this);
697 #ifdef DEBUG_WRITERFILTER
698 string
OOXMLUniversalMeasureValue::toString() const
700 return OString::number(mnValue
).getStr();
705 class OOXMLShapeValue
709 OOXMLShapeValue::OOXMLShapeValue(uno::Reference
<drawing::XShape
> rShape
)
714 OOXMLShapeValue::~OOXMLShapeValue()
718 uno::Any
OOXMLShapeValue::getAny() const
720 return uno::Any(mrShape
);
723 #ifdef DEBUG_WRITERFILTER
724 string
OOXMLShapeValue::toString() const
730 OOXMLValue
* OOXMLShapeValue::clone() const
732 return new OOXMLShapeValue(mrShape
);
736 class OOXMLStarMathValue
740 OOXMLStarMathValue::OOXMLStarMathValue( uno::Reference
< embed::XEmbeddedObject
> c
)
745 OOXMLStarMathValue::~OOXMLStarMathValue()
749 uno::Any
OOXMLStarMathValue::getAny() const
751 return uno::Any(component
);
754 #ifdef DEBUG_WRITERFILTER
755 string
OOXMLStarMathValue::toString() const
761 OOXMLValue
* OOXMLStarMathValue::clone() const
763 return new OOXMLStarMathValue( component
);
770 OOXMLTableImpl::OOXMLTableImpl()
774 OOXMLTableImpl::~OOXMLTableImpl()
778 void OOXMLTableImpl::resolve(Table
& rTable
)
780 Table
* pTable
= &rTable
;
784 PropertySets_t::iterator it
= mPropertySets
.begin();
785 PropertySets_t::iterator itEnd
= mPropertySets
.end();
789 writerfilter::Reference
<Properties
>::Pointer_t pProperties
790 ((*it
)->getProperties());
792 if (pProperties
.get() != nullptr)
793 pTable
->entry(nPos
, pProperties
);
800 void OOXMLTableImpl::add(ValuePointer_t pPropertySet
)
802 if (pPropertySet
.get() != nullptr)
803 mPropertySets
.push_back(pPropertySet
);
806 OOXMLTable
* OOXMLTableImpl::clone() const
808 return new OOXMLTableImpl(*this);
812 class: OOXMLPropertySetEntryToString
815 OOXMLPropertySetEntryToString::OOXMLPropertySetEntryToString(Id nId
)
820 OOXMLPropertySetEntryToString::~OOXMLPropertySetEntryToString()
824 void OOXMLPropertySetEntryToString::sprm(Sprm
& /*rSprm*/)
828 void OOXMLPropertySetEntryToString::attribute(Id nId
, Value
& rValue
)
831 mStr
= rValue
.getString();
835 class: OOXMLPropertySetEntryToInteger
838 OOXMLPropertySetEntryToInteger::OOXMLPropertySetEntryToInteger(Id nId
)
839 : mnId(nId
), mnValue(0)
843 OOXMLPropertySetEntryToInteger::~OOXMLPropertySetEntryToInteger()
847 void OOXMLPropertySetEntryToInteger::sprm(Sprm
& /*rSprm*/)
851 void OOXMLPropertySetEntryToInteger::attribute(Id nId
, Value
& rValue
)
854 mnValue
= rValue
.getInt();
858 class: OOXMLPropertySetEntryToBool
861 OOXMLPropertySetEntryToBool::OOXMLPropertySetEntryToBool(Id nId
)
862 : mnId(nId
), mValue(false)
865 OOXMLPropertySetEntryToBool::~OOXMLPropertySetEntryToBool() {}
867 void OOXMLPropertySetEntryToBool::sprm(Sprm
& /*rSprm*/) {}
869 void OOXMLPropertySetEntryToBool::attribute(Id nId
, Value
& rValue
)
872 mValue
= (rValue
.getInt() != 0);
877 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */