update emoji autocorrect entries from po-files
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLPropertySetImpl.cxx
blob64a728550d5b56d25f1e1df379e8b478aa6b5c41
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 "OOXMLPropertySetImpl.hxx"
21 #include <stdio.h>
22 #include <iostream>
23 #include <ooxml/QNameToString.hxx>
24 #include <com/sun/star/drawing/XShape.hpp>
25 #include <oox/token/tokens.hxx>
27 namespace writerfilter {
28 namespace ooxml
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
62 return mId;
65 Value::Pointer_t OOXMLPropertyImpl::getValue()
67 Value::Pointer_t pResult;
69 if (mpValue.get() != nullptr)
70 pResult = Value::Pointer_t(mpValue->clone());
71 else
72 pResult = Value::Pointer_t(new OOXMLValue());
74 return pResult;
77 writerfilter::Reference<BinaryObj>::Pointer_t OOXMLPropertyImpl::getBinary()
79 writerfilter::Reference<BinaryObj>::Pointer_t pResult;
81 if (mpValue.get() != nullptr)
82 pResult = mpValue->getBinary();
84 return pResult;
87 writerfilter::Reference<Stream>::Pointer_t OOXMLPropertyImpl::getStream()
89 writerfilter::Reference<Stream>::Pointer_t pResult;
91 if (mpValue.get() != nullptr)
92 pResult = mpValue->getStream();
94 return pResult;
97 writerfilter::Reference<Properties>::Pointer_t OOXMLPropertyImpl::getProps()
99 writerfilter::Reference<Properties>::Pointer_t pResult;
101 if (mpValue.get() != nullptr)
102 pResult = mpValue->getProperties();
104 return pResult;
107 #ifdef DEBUG_WRITERFILTER
108 string OOXMLPropertyImpl::getName() const
110 string sResult;
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);
122 sResult = sBuffer;
125 return sResult;
127 #endif
129 #ifdef DEBUG_WRITERFILTER
130 string OOXMLPropertyImpl::toString() const
132 string sResult = "(";
134 sResult += getName();
135 sResult += ", ";
136 if (mpValue.get() != nullptr)
137 sResult += mpValue->toString();
138 else
139 sResult +="(null)";
140 sResult +=")";
142 return sResult;
144 #endif
146 Sprm * OOXMLPropertyImpl::clone()
148 return new OOXMLPropertyImpl(*this);
151 void OOXMLPropertyImpl::resolve(writerfilter::Properties & rProperties)
153 writerfilter::Properties * pProperties = nullptr;
154 pProperties = &rProperties;
156 switch (meType)
158 case SPRM:
159 if (mId != 0x0)
160 pProperties->sprm(*this);
161 break;
162 case ATTRIBUTE:
163 pProperties->attribute(mId, *getValue());
164 break;
169 class OOXMLValue
172 OOXMLValue::OOXMLValue()
176 OOXMLValue::~OOXMLValue()
180 bool OOXMLValue::getBool() const
182 return false;
185 int OOXMLValue::getInt() const
187 return 0;
190 OUString OOXMLValue::getString() const
192 return OUString();
195 uno::Any OOXMLValue::getAny() const
197 return uno::Any();
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
218 return "OOXMLValue";
220 #endif
222 OOXMLValue * OOXMLValue::clone() const
224 return new OOXMLValue(*this);
228 class OOXMLBinaryValue
231 OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t
232 pBinaryObj)
233 : mpBinaryObj(pBinaryObj)
237 OOXMLBinaryValue::~OOXMLBinaryValue()
241 writerfilter::Reference<BinaryObj>::Pointer_t OOXMLBinaryValue::getBinary()
243 return mpBinaryObj;
246 #ifdef DEBUG_WRITERFILTER
247 string OOXMLBinaryValue::toString() const
249 return "BinaryObj";
251 #endif
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)
285 : mbValue(bValue)
289 OOXMLBooleanValue::~OOXMLBooleanValue()
293 bool OOXMLBooleanValue::getBool() const
295 return mbValue;
298 int OOXMLBooleanValue::getInt() const
300 return mbValue ? 1 : 0;
303 uno::Any OOXMLBooleanValue::getAny() const
305 uno::Any aResult(mbValue);
307 return aResult;
310 #ifdef DEBUG_WRITERFILTER
311 string OOXMLBooleanValue::toString() const
313 return mbValue ? "true" : "false";
315 #endif
317 OOXMLValue * OOXMLBooleanValue::clone() const
319 return new OOXMLBooleanValue(*this);
323 class OOXMLStringValue
326 OOXMLStringValue::OOXMLStringValue(const OUString & rStr)
327 : mStr(rStr)
331 OOXMLStringValue::~OOXMLStringValue()
335 uno::Any OOXMLStringValue::getAny() const
337 uno::Any aAny(mStr);
339 return aAny;
342 OUString OOXMLStringValue::getString() const
344 return mStr;
347 #ifdef DEBUG_WRITERFILTER
348 string OOXMLStringValue::toString() const
350 return OUStringToOString(mStr, RTL_TEXTENCODING_ASCII_US).getStr();
352 #endif
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);
375 return aAny;
378 #ifdef DEBUG_WRITERFILTER
379 string OOXMLInputStreamValue::toString() const
381 return "InputStream";
383 #endif
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)
400 bResult = true;
401 else if (x.get() != nullptr && y.get() != nullptr)
402 bResult = x->getId() < y->getId();
404 return bResult;
408 class OOXMLPropertySetImpl
411 OOXMLPropertySetImpl::OOXMLPropertySetImpl()
413 static OString aName("OOXMLPropertySetImpl");
414 maType = aName;
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());
473 if (pSet != nullptr)
475 mProperties.resize(mProperties.size() + pSet->mProperties.size());
476 for (OOXMLProperties_t::iterator aIt = pSet->mProperties.begin();
477 aIt != pSet->mProperties.end(); ++aIt)
478 add(*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 = "[";
497 char sBuffer[256];
498 snprintf(sBuffer, sizeof(sBuffer), "%p", this);
499 sResult += sBuffer;
500 sResult += ":";
502 OOXMLProperties_t::iterator aItBegin = begin();
503 OOXMLProperties_t::iterator aItEnd = end();
505 for (OOXMLProperties_t::iterator aIt = aItBegin; aIt != aItEnd; ++aIt)
507 if (aIt != aItBegin)
508 sResult += ", ";
510 if ((*aIt).get() != nullptr)
511 sResult += (*aIt)->toString();
512 else
513 sResult += "0x0";
516 sResult += "]";
518 return sResult;
520 #endif
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
545 char sBuffer[256];
547 snprintf(sBuffer, sizeof(sBuffer), "t:%p, m:%p", this, mpPropertySet.get());
549 return "OOXMLPropertySetValue(" + string(sBuffer) + ")";
551 #endif
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));
575 switch (nValue) {
576 case 0: return Zero;
577 case 1: return One;
578 case 2: return Two;
579 case 3: return Three;
580 case 4: return Four;
581 case 5: return Five;
582 case 6: return Six;
583 case 7: return Seven;
584 case 8: return Eight;
585 case 9: return Nine;
586 default: break;
589 OOXMLValue::Pointer_t value(new OOXMLIntegerValue(nValue));
591 return value;
594 OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue)
595 : mnValue(nValue)
599 OOXMLIntegerValue::~OOXMLIntegerValue()
603 int OOXMLIntegerValue::getInt() const
605 return mnValue;
608 uno::Any OOXMLIntegerValue::getAny() const
610 uno::Any aResult(mnValue);
612 return aResult;
615 OOXMLValue * OOXMLIntegerValue::clone() const
617 return new OOXMLIntegerValue(*this);
620 #ifdef DEBUG_WRITERFILTER
621 string OOXMLIntegerValue::toString() const
623 char buffer[256];
624 snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, mnValue);
626 return buffer;
628 #endif
631 class OOXMLHexValue
634 OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue)
635 : mnValue(nValue)
639 OOXMLHexValue::OOXMLHexValue(const char * pValue)
641 mnValue = rtl_str_toUInt32(pValue, 16);
644 OOXMLHexValue::~OOXMLHexValue()
648 int OOXMLHexValue::getInt() const
650 return mnValue;
653 OOXMLValue * OOXMLHexValue::clone() const
655 return new OOXMLHexValue(*this);
658 #ifdef DEBUG_WRITERFILTER
659 string OOXMLHexValue::toString() const
661 char buffer[256];
662 snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, mnValue);
664 return buffer;
666 #endif
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);
675 if (nLen > 2 &&
676 pValue[nLen-2] == 'p' &&
677 pValue[nLen-1] == 't')
679 mnValue = mnValue * 20;
683 OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue()
687 int OOXMLUniversalMeasureValue::getInt() const
689 return mnValue;
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();
702 #endif
705 class OOXMLShapeValue
709 OOXMLShapeValue::OOXMLShapeValue(uno::Reference<drawing::XShape> rShape)
710 : mrShape(rShape)
714 OOXMLShapeValue::~OOXMLShapeValue()
718 uno::Any OOXMLShapeValue::getAny() const
720 return uno::Any(mrShape);
723 #ifdef DEBUG_WRITERFILTER
724 string OOXMLShapeValue::toString() const
726 return "Shape";
728 #endif
730 OOXMLValue * OOXMLShapeValue::clone() const
732 return new OOXMLShapeValue(mrShape);
736 class OOXMLStarMathValue
740 OOXMLStarMathValue::OOXMLStarMathValue( uno::Reference< embed::XEmbeddedObject > c )
741 : component(c)
745 OOXMLStarMathValue::~OOXMLStarMathValue()
749 uno::Any OOXMLStarMathValue::getAny() const
751 return uno::Any(component);
754 #ifdef DEBUG_WRITERFILTER
755 string OOXMLStarMathValue::toString() const
757 return "StarMath";
759 #endif
761 OOXMLValue * OOXMLStarMathValue::clone() const
763 return new OOXMLStarMathValue( component );
767 class OOXMLTableImpl
770 OOXMLTableImpl::OOXMLTableImpl()
774 OOXMLTableImpl::~OOXMLTableImpl()
778 void OOXMLTableImpl::resolve(Table & rTable)
780 Table * pTable = &rTable;
782 int nPos = 0;
784 PropertySets_t::iterator it = mPropertySets.begin();
785 PropertySets_t::iterator itEnd = mPropertySets.end();
787 while (it != itEnd)
789 writerfilter::Reference<Properties>::Pointer_t pProperties
790 ((*it)->getProperties());
792 if (pProperties.get() != nullptr)
793 pTable->entry(nPos, pProperties);
795 ++nPos;
796 ++it;
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)
816 : mnId(nId)
820 OOXMLPropertySetEntryToString::~OOXMLPropertySetEntryToString()
824 void OOXMLPropertySetEntryToString::sprm(Sprm & /*rSprm*/)
828 void OOXMLPropertySetEntryToString::attribute(Id nId, Value & rValue)
830 if (nId == mnId)
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)
853 if (nId == mnId)
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)
871 if (nId == mnId)
872 mValue = (rValue.getInt() != 0);
877 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */