1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <stdio.h>
25 #include <iostream>
26 #include <set>
27 #include <rtl/uuid.h>
28 #include <com/sun/star/drawing/XShapes.hpp>
29 #include <resourcemodel/QNameToString.hxx>
30 #include <resourcemodel/XPathLogger.hxx>
31 #include <resourcemodel/util.hxx>
32 #include <ooxml/resourceids.hxx>
33 #include <doctok/sprmids.hxx>
34 #include <ooxml/OOXMLnamespaceids.hxx>
35 #include "OOXMLFastContextHandler.hxx"
36 #include "OOXMLFactory.hxx"
37 #include "Handler.hxx"
38 #include "ooxmlLoggers.hxx"
39 
40 static const ::rtl::OUString aEmptyStr;
41 
42 static const sal_uInt8 s0x7[] = { 0x7, 0x0 };
43 static const sal_uInt8 s0xd[] = { 0xd, 0x0 };
44 static const sal_uInt8 sCR[] = { 0xd, 0x0 };
45 static const sal_uInt8 sFtnEdnRef[] = { 0x2, 0x0 };
46 static const sal_uInt8 sFtnEdnSep[] = { 0x3, 0x0 };
47 static const sal_uInt8 sFtnEdnCont[] = { 0x4, 0x0 };
48 static const sal_uInt8 sTab[] = { 0x9, 0x0 };
49 static const sal_uInt8 sPgNum[] = { 0x0, 0x0 };
50 static const sal_uInt8 sFieldStart[] = { 0x13  };
51 static const sal_uInt8 sFieldSep[] = { 0x14 };
52 static const sal_uInt8 sFieldEnd[] = { 0x15 };
53 static const sal_uInt8 sNoBreakHyphen[] = { 0x1e, 0x0 };
54 static const sal_uInt8 sSoftHyphen[] = { 0x1f, 0x0 };
55 
56 namespace writerfilter {
57 namespace ooxml
58 {
59 using ::com::sun::star::lang::XMultiComponentFactory;
60 using namespace ::com::sun::star;
61 using namespace ::std;
62 
CreateUnoTunnelId()63 static uno::Sequence< sal_Int8 >  CreateUnoTunnelId()
64 {
65 	static osl::Mutex aCreateMutex;
66 	osl::Guard<osl::Mutex> aGuard( aCreateMutex );
67 	uno::Sequence< sal_Int8 > aSeq( 16 );
68 	rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0,	sal_True );
69 	return aSeq;
70 }
71 
resourceToString(OOXMLFastContextHandler::ResourceEnum_t eResource)72 static string resourceToString
73 (OOXMLFastContextHandler::ResourceEnum_t eResource)
74 {
75     string sResult;
76 
77     switch (eResource)
78     {
79     case OOXMLFastContextHandler::STREAM:
80         sResult = "Stream";
81         break;
82     case OOXMLFastContextHandler::PROPERTIES:
83         sResult = "Properties";
84         break;
85     case OOXMLFastContextHandler::TABLE:
86         sResult = "Table";
87         break;
88     case OOXMLFastContextHandler::SHAPE:
89         sResult = "Shape";
90         break;
91     default:
92         sResult = "??";
93     }
94 
95     return sResult;
96 }
97 
98 set<OOXMLFastContextHandler *> aSetContexts;
99 
100 #ifdef DEBUG
101 class OOXMLIdToString : public IdToString
102 {
103 public:
OOXMLIdToString()104     OOXMLIdToString() : IdToString() {}
~OOXMLIdToString()105     virtual ~OOXMLIdToString() {}
106 
toString(const Id & rId) const107     virtual string toString(const Id & rId) const
108     {
109         string s((*QNameToString::Instance())(rId));
110 
111         if (s.size() == 0)
112             s = "(fasttoken)" + fastTokenToId(rId);
113         else
114             s = "(qname)" + s;
115 
116         return s;
117     }
118 };
119 #endif
120 
121 /*
122   class OOXMLFastContextHandler
123  */
124 
125 sal_uInt32 OOXMLFastContextHandler::mnInstanceCount = 0;
126 
OOXMLFastContextHandler(uno::Reference<uno::XComponentContext> const & context)127 OOXMLFastContextHandler::OOXMLFastContextHandler
128 (uno::Reference< uno::XComponentContext > const & context)
129 : mpParent(NULL),
130   mId(0),
131   mnDefine(0),
132   mnToken(OOXML_FAST_TOKENS_END),
133   mpStream(NULL),
134   mnTableDepth(0),
135   mnInstanceNumber(mnInstanceCount),
136   mnRefCount(0),
137   m_xContext(context)
138 {
139     mnInstanceCount++;
140     aSetContexts.insert(this);
141 
142     if (mpParserState.get() == NULL)
143         mpParserState.reset(new OOXMLParserState());
144 
145     mpParserState->incContextCount();
146 }
147 
OOXMLFastContextHandler(OOXMLFastContextHandler * pContext)148 OOXMLFastContextHandler::OOXMLFastContextHandler
149 (OOXMLFastContextHandler * pContext)
150 : cppu::WeakImplHelper1<com::sun::star::xml::sax::XFastContextHandler>(),
151   mpParent(pContext),
152   mId(0),
153   mnDefine(0),
154   mnToken(OOXML_FAST_TOKENS_END),
155   mpStream(NULL),
156   mnTableDepth(0),
157   mnInstanceNumber(mnInstanceCount),
158   mnRefCount(0),
159   m_xContext(pContext->m_xContext)
160 {
161     if (pContext != NULL)
162     {
163         mpStream = pContext->mpStream;
164         mpParserState = pContext->mpParserState;
165         mnTableDepth = pContext->mnTableDepth;
166         m_xContext = pContext->m_xContext;
167     }
168 
169     if (mpParserState.get() == NULL)
170         mpParserState.reset(new OOXMLParserState());
171 
172     mnInstanceCount++;
173     aSetContexts.insert(this);
174     mpParserState->incContextCount();
175 }
176 
~OOXMLFastContextHandler()177 OOXMLFastContextHandler::~OOXMLFastContextHandler()
178 {
179     aSetContexts.erase(this);
180 }
181 
182 // ::com::sun::star::xml::sax::XFastContextHandler:
startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)183 void SAL_CALL OOXMLFastContextHandler::startFastElement
184 (sal_Int32 Element,
185  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
186     throw (uno::RuntimeException, xml::sax::SAXException)
187 {
188 #ifdef DEBUG_CONTEXT_HANDLER
189     debug_logger->startElement("contexthandler.element");
190     string sToken = fastTokenToId(Element);
191     mpParserState->getXPathLogger().startElement(sToken);
192     debug_logger->attribute("token", sToken);
193     debug_logger->attribute("type", getType());
194     debug_logger->attribute("xpath", mpParserState->getXPathLogger().getXPath());
195     debug_logger->startElement("at-start");
196     debug_logger->addTag(toTag());
197     debug_logger->endElement("at-start");
198 #endif
199     attributes(Attribs);
200     lcl_startFastElement(Element, Attribs);
201 }
202 
startUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> &)203 void SAL_CALL OOXMLFastContextHandler::startUnknownElement
204 (const ::rtl::OUString & Namespace, const ::rtl::OUString & Name,
205  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
206 throw (uno::RuntimeException, xml::sax::SAXException)
207 {
208 #ifdef DEBUG_CONTEXT_HANDLER
209     debug_logger->startElement("contexthandler.unknown-element");
210     debug_logger->attribute("namespace", Namespace);
211     debug_logger->attribute("name", Name);
212     mpParserState->getXPathLogger().startElement("unknown");
213 #else
214     (void) Namespace;
215     (void) Name;
216 #endif
217 }
218 
endFastElement(sal_Int32 Element)219 void SAL_CALL OOXMLFastContextHandler::endFastElement(sal_Int32 Element)
220 throw (uno::RuntimeException, xml::sax::SAXException)
221 {
222 #ifdef DEBUG_CONTEXT_HANDLER
223     string sToken = fastTokenToId(Element);
224     (void) sToken;
225 #endif
226 
227     lcl_endFastElement(Element);
228 
229 #ifdef DEBUG_CONTEXT_HANDLER
230     debug_logger->startElement("at-end");
231     debug_logger->addTag(toTag());
232     debug_logger->endElement("at-end");
233     debug_logger->endElement("contexthandler.element");
234     mpParserState->getXPathLogger().endElement();
235 #endif
236 }
237 
lcl_startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> &)238 void OOXMLFastContextHandler::lcl_startFastElement
239 (sal_Int32 Element,
240  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
241     throw (uno::RuntimeException, xml::sax::SAXException)
242 {
243     OOXMLFactory::getInstance()->startAction(this, Element);
244 }
245 
lcl_endFastElement(sal_Int32 Element)246 void OOXMLFastContextHandler::lcl_endFastElement
247 (sal_Int32 Element)
248     throw (uno::RuntimeException, xml::sax::SAXException)
249 {
250     OOXMLFactory::getInstance()->endAction(this, Element);
251 }
252 
endUnknownElement(const::rtl::OUString &,const::rtl::OUString &)253 void SAL_CALL OOXMLFastContextHandler::endUnknownElement
254 (const ::rtl::OUString & , const ::rtl::OUString & )
255 throw (uno::RuntimeException, xml::sax::SAXException)
256 {
257 #ifdef DEBUG_CONTEXT_HANDLER
258     debug_logger->endElement("contexthandler.unknown-element");
259     mpParserState->getXPathLogger().endElement();
260 #endif
261 }
262 
263 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)264  OOXMLFastContextHandler::createFastChildContext
265 (sal_Int32 Element,
266  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
267     throw (uno::RuntimeException, xml::sax::SAXException)
268 {
269 #ifdef DEBUG_CONTEXT_HANDLER
270     debug_logger->startElement("contexthandler.createFastChildContext");
271     debug_logger->attribute("token", fastTokenToId(Element));
272     debug_logger->attribute("type", getType());
273 #endif
274 
275     uno::Reference< xml::sax::XFastContextHandler > xResult
276         (lcl_createFastChildContext(Element, Attribs));
277 
278 #ifdef DEBUG_CONTEXT_HANDLER
279     debug_logger->endElement("contexthandler.createFastChildContext");
280 #endif
281 
282     return xResult;
283 }
284 
285 uno::Reference< xml::sax::XFastContextHandler >
lcl_createFastChildContext(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> &)286  OOXMLFastContextHandler::lcl_createFastChildContext
287 (sal_Int32 Element,
288  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
289     throw (uno::RuntimeException, xml::sax::SAXException)
290 {
291     return OOXMLFactory::getInstance()->createFastChildContext(this, Element);
292 }
293 
294 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> &)295 OOXMLFastContextHandler::createUnknownChildContext
296 (const ::rtl::OUString & Namespace,
297  const ::rtl::OUString & Name,
298  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
299     throw (uno::RuntimeException, xml::sax::SAXException)
300 {
301 #ifdef DEBUG_CONTEXT_HANDLER
302     debug_logger->startElement("contexthandler.createUnknownChildContext");
303     debug_logger->attribute("namespace", Namespace);
304     debug_logger->attribute("name", Name);
305     debug_logger->endElement("contexthandler.createUnknownChildContext");
306 #else
307     (void) Namespace;
308     (void) Name;
309 #endif
310 
311     return uno::Reference< xml::sax::XFastContextHandler >
312         (new OOXMLFastContextHandler(*const_cast<const OOXMLFastContextHandler *>(this)));
313 }
314 
characters(const::rtl::OUString & aChars)315 void SAL_CALL OOXMLFastContextHandler::characters
316 (const ::rtl::OUString & aChars)
317     throw (uno::RuntimeException, xml::sax::SAXException)
318 {
319     lcl_characters(aChars);
320 }
321 
lcl_characters(const::rtl::OUString & rString)322 void OOXMLFastContextHandler::lcl_characters
323 (const ::rtl::OUString & rString)
324 throw (uno::RuntimeException, xml::sax::SAXException)
325 {
326     OOXMLFactory::getInstance()->characters(this, rString);
327 }
328 
getUnoTunnelId()329 const uno::Sequence< sal_Int8 > & OOXMLFastContextHandler::getUnoTunnelId()
330 {
331     static uno::Sequence< sal_Int8 > aSeq = CreateUnoTunnelId();
332 	return aSeq;
333 }
334 
getSomething(const uno::Sequence<sal_Int8> & rId)335 sal_Int64 SAL_CALL OOXMLFastContextHandler::getSomething( const uno::Sequence< sal_Int8 >& rId )
336 	throw(uno::RuntimeException)
337 {
338     if( rId.getLength() == 16
339         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
340                                    rId.getConstArray(), 16 ) )
341     {
342         return sal::static_int_cast<sal_Int64>
343             (reinterpret_cast<sal_IntPtr>(this));
344     }
345 
346     return 0x0;
347 }
348 
setStream(Stream * pStream)349 void OOXMLFastContextHandler::setStream(Stream * pStream)
350 {
351     mpStream = pStream;
352 }
353 
getValue() const354 OOXMLValue::Pointer_t OOXMLFastContextHandler::getValue() const
355 {
356     return OOXMLValue::Pointer_t();
357 }
358 
attributes(const uno::Reference<xml::sax::XFastAttributeList> & Attribs)359 void OOXMLFastContextHandler::attributes
360 (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
361  throw (uno::RuntimeException, xml::sax::SAXException)
362 {
363     OOXMLFactory::getInstance()->attributes(this, Attribs);
364 }
365 
startAction(sal_Int32 Element)366 void OOXMLFastContextHandler::startAction(sal_Int32 Element)
367 {
368 #ifdef DEBUG_CONTEXT_HANDLER
369     debug_logger->startElement("contexthandler.startAction");
370 #endif
371     lcl_startAction(Element);
372 #ifdef DEBUG_CONTEXT_HANDLER
373     debug_logger->endElement("contexthandler.startAction");
374 #endif
375 }
376 
lcl_startAction(sal_Int32 Element)377 void OOXMLFastContextHandler::lcl_startAction(sal_Int32 Element)
378 {
379     OOXMLFactory::getInstance()->startAction(this, Element);
380 }
381 
endAction(sal_Int32 Element)382 void OOXMLFastContextHandler::endAction(sal_Int32 Element)
383 {
384 #ifdef DEBUG_CONTEXT_HANDLER
385     debug_logger->startElement("contexthandler.endAction");
386 #endif
387     lcl_endAction(Element);
388 #ifdef DEBUG_CONTEXT_HANDLER
389     debug_logger->endElement("contexthandler.endAction");
390 #endif
391 }
392 
lcl_endAction(sal_Int32 Element)393 void OOXMLFastContextHandler::lcl_endAction(sal_Int32 Element)
394 {
395     OOXMLFactory::getInstance()->endAction(this, Element);
396 }
397 
398 #ifdef DEBUG
toPropertiesTag(OOXMLPropertySet::Pointer_t pProps)399 XMLTag::Pointer_t OOXMLFastContextHandler::toPropertiesTag
400     (OOXMLPropertySet::Pointer_t pProps)
401 {
402     XMLTag::Pointer_t pTag;
403 
404     if (pProps.get() != NULL)
405     {
406         PropertySetToTagHandler aHandler(IdToString::Pointer_t(new OOXMLIdToString()));
407 
408         pProps->resolve(aHandler);
409         pTag = aHandler.getTag();
410     }
411 
412     return pTag;
413 }
414 
toTag() const415 XMLTag::Pointer_t OOXMLFastContextHandler::toTag() const
416 {
417     XMLTag::Pointer_t pTag(new XMLTag("context"));
418 
419     static char sBuffer[128];
420     snprintf(sBuffer, sizeof(sBuffer), "%p", this);
421 
422     pTag->addAttr("parent", sBuffer);
423     pTag->addAttr("type", getType());
424     pTag->addAttr("resource", getResourceString());
425     pTag->addAttr("token", fastTokenToId(getToken()));
426     pTag->addAttr("id", (*QNameToString::Instance())(getId()));
427 
428     OOXMLValue::Pointer_t pVal(getValue());
429 
430     if (pVal.get() != NULL)
431         pTag->addAttr("value", pVal->toString());
432     else
433         pTag->addAttr("value", "(null)");
434 
435     XMLTag::Pointer_t pTagProps(toPropertiesTag(getPropertySet()));
436     if (pTagProps.get() != NULL)
437         pTag->addTag(pTagProps);
438 
439     pTag->addTag(mpParserState->toTag());
440 
441     return pTag;
442 }
443 
toString() const444 string OOXMLFastContextHandler::toString() const
445 {
446     return toTag()->toString();
447 }
448 #endif
449 
getResourceString() const450 string OOXMLFastContextHandler::getResourceString() const
451 {
452     return resourceToString(getResource());
453 }
454 
setId(Id rId)455 void OOXMLFastContextHandler::setId(Id rId)
456 {
457 #ifdef DEBUG_CONTEXT_HANDLER
458     debug_logger->startElement("contexthandler.setId");
459 
460     static char sBuffer[256];
461     snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, rId);
462 
463     debug_logger->attribute("id", sBuffer);
464     debug_logger->attribute("name", (*QNameToString::Instance())(rId));
465     debug_logger->endElement("contexthandler.setId");
466 #endif
467 
468     mId = rId;
469 }
470 
getId() const471 Id OOXMLFastContextHandler::getId() const
472 {
473     return mId;
474 }
475 
setDefine(Id nDefine)476 void OOXMLFastContextHandler::setDefine(Id nDefine)
477 {
478     mnDefine = nDefine;
479 }
480 
getDefine() const481 Id OOXMLFastContextHandler::getDefine() const
482 {
483     return mnDefine;
484 }
485 
getParserState() const486 OOXMLParserState::Pointer_t OOXMLFastContextHandler::getParserState() const
487 {
488     return mpParserState;
489 }
490 
setToken(Token_t nToken)491 void OOXMLFastContextHandler::setToken(Token_t nToken)
492 {
493     mnToken = nToken;
494 }
495 
getToken() const496 Token_t OOXMLFastContextHandler::getToken() const
497 {
498     return mnToken;
499 }
500 
mark(const Id & rId,OOXMLValue::Pointer_t pVal)501 void OOXMLFastContextHandler::mark(const Id & rId, OOXMLValue::Pointer_t pVal)
502 {
503     OOXMLPropertySetImpl::Pointer_t pPropSet(new OOXMLPropertySetImpl());
504     OOXMLPropertyImpl::Pointer_t pProperty
505         (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
506 
507     pPropSet->add(pProperty);
508     mpStream->props(pPropSet);
509 }
510 
setParent(OOXMLFastContextHandler * pParent)511 void OOXMLFastContextHandler::setParent
512 (OOXMLFastContextHandler * pParent)
513 {
514     mpParent = pParent;
515 }
516 
getPicturePropSet(const::rtl::OUString & rId)517 OOXMLPropertySet * OOXMLFastContextHandler::getPicturePropSet
518 (const ::rtl::OUString & rId)
519 {
520     return dynamic_cast<OOXMLDocumentImpl *>(mpParserState->getDocument())->
521         getPicturePropSet(rId);
522 }
523 
sendTableDepth() const524 void OOXMLFastContextHandler::sendTableDepth() const
525 {
526 #ifdef DEBUG_CONTEXT_HANDLER
527     debug_logger->startElement("contexthandler.sendTableDepth");
528 #endif
529 
530     if (mnTableDepth > 0)
531     {
532         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
533         {
534             OOXMLValue::Pointer_t pVal
535                 (new OOXMLIntegerValue(mnTableDepth));
536             OOXMLProperty::Pointer_t pProp
537                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
538             pProps->add(pProp);
539         }
540         {
541             OOXMLValue::Pointer_t pVal
542                 (new OOXMLIntegerValue(1));
543             OOXMLProperty::Pointer_t pProp
544                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
545             pProps->add(pProp);
546         }
547 
548         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
549     }
550 #ifdef DEBUG_CONTEXT_HANDLER
551     debug_logger->endElement("contexthandler.sendTableDepth");
552 #endif
553 }
554 
setHandle()555 void OOXMLFastContextHandler::setHandle()
556 {
557     mpParserState->setHandle();
558     mpStream->info(mpParserState->getHandle());
559 }
560 
startCharacterGroup()561 void OOXMLFastContextHandler::startCharacterGroup()
562 {
563 #ifdef DEBUG_CONTEXT_HANDLER
564     debug_logger->element("contexthandler.startCharacterGroup");
565 #endif
566 
567     if (isForwardEvents())
568     {
569         if (mpParserState->isInCharacterGroup())
570             endCharacterGroup();
571 
572         if (! mpParserState->isInParagraphGroup())
573             startParagraphGroup();
574 
575         if (! mpParserState->isInCharacterGroup())
576         {
577             mpStream->startCharacterGroup();
578             mpParserState->setInCharacterGroup(true);
579             mpParserState->resolveCharacterProperties(*mpStream);
580         }
581     }
582 }
583 
endCharacterGroup()584 void OOXMLFastContextHandler::endCharacterGroup()
585 {
586 #ifdef DEBUG_CONTEXT_HANDLER
587     debug_logger->element("contexthandler.endCharacterGroup");
588 #endif
589 
590     if (isForwardEvents() && mpParserState->isInCharacterGroup())
591     {
592         mpStream->endCharacterGroup();
593         mpParserState->setInCharacterGroup(false);
594     }
595 }
596 
startParagraphGroup()597 void OOXMLFastContextHandler::startParagraphGroup()
598 {
599 #ifdef DEBUG_CONTEXT_HANDLER
600     debug_logger->element("contexthandler.startParagraphGroup");
601 #endif
602 
603     if (isForwardEvents())
604     {
605         if (mpParserState->isInParagraphGroup())
606             endParagraphGroup();
607 
608         if (! mpParserState->isInSectionGroup())
609             startSectionGroup();
610 
611         if (! mpParserState->isInParagraphGroup())
612         {
613             mpStream->startParagraphGroup();
614             mpParserState->setInParagraphGroup(true);
615         }
616     }
617 }
618 
endParagraphGroup()619 void OOXMLFastContextHandler::endParagraphGroup()
620 {
621 #ifdef DEBUG_CONTEXT_HANDLER
622     debug_logger->element("contexthandler.endParagraphGroup");
623 #endif
624 
625     if (isForwardEvents())
626     {
627         if (mpParserState->isInCharacterGroup())
628             endCharacterGroup();
629 
630         if (mpParserState->isInParagraphGroup())
631         {
632             mpStream->endParagraphGroup();
633             mpParserState->setInParagraphGroup(false);
634         }
635     }
636 }
637 
startSectionGroup()638 void OOXMLFastContextHandler::startSectionGroup()
639 {
640 #ifdef DEBUG_CONTEXT_HANDLER
641     debug_logger->element("contexthandler.startSectionGroup");
642 #endif
643 
644     if (isForwardEvents())
645     {
646         if (mpParserState->isInSectionGroup())
647             endSectionGroup();
648 
649         if (! mpParserState->isInSectionGroup())
650         {
651             mpStream->info(mpParserState->getHandle());
652             mpStream->startSectionGroup();
653             mpParserState->setInSectionGroup(true);
654         }
655     }
656 }
657 
endSectionGroup()658 void OOXMLFastContextHandler::endSectionGroup()
659 {
660 #ifdef DEBUG_CONTEXT_HANDLER
661     debug_logger->element("contexthandler.endSectionGroup");
662 #endif
663 
664     if (isForwardEvents())
665     {
666         if (mpParserState->isInParagraphGroup())
667             endParagraphGroup();
668 
669         if (mpParserState->isInSectionGroup())
670         {
671             mpStream->endSectionGroup();
672             mpParserState->setInSectionGroup(false);
673         }
674     }
675 }
676 
setLastParagraphInSection()677 void OOXMLFastContextHandler::setLastParagraphInSection()
678 {
679     mpParserState->setLastParagraphInSection(true);
680     mpStream->markLastParagraphInSection( );
681 }
682 
newProperty(const Id &,OOXMLValue::Pointer_t)683 void OOXMLFastContextHandler::newProperty
684 (const Id & /*nId*/, OOXMLValue::Pointer_t /*pVal*/)
685 {
686 }
687 
setPropertySet(OOXMLPropertySet::Pointer_t)688 void OOXMLFastContextHandler::setPropertySet
689 (OOXMLPropertySet::Pointer_t /* pPropertySet */)
690 {
691 }
692 
getPropertySet() const693 OOXMLPropertySet::Pointer_t OOXMLFastContextHandler::getPropertySet() const
694 {
695     return OOXMLPropertySet::Pointer_t();
696 }
697 
startField()698 void OOXMLFastContextHandler::startField()
699 {
700 #ifdef DEBUG_CONTEXT_HANDLER
701     debug_logger->element("contexthandler.startField");
702 #endif
703     startCharacterGroup();
704     if (isForwardEvents())
705         mpStream->text(sFieldStart, 1);
706     endCharacterGroup();
707 }
708 
fieldSeparator()709 void OOXMLFastContextHandler::fieldSeparator()
710 {
711 #ifdef DEBUG_CONTEXT_HANDLER
712     debug_logger->element("contexthandler.fieldSeparator");
713 #endif
714     startCharacterGroup();
715     if (isForwardEvents())
716         mpStream->text(sFieldSep, 1);
717     endCharacterGroup();
718 }
719 
endField()720 void OOXMLFastContextHandler::endField()
721 {
722 #ifdef DEBUG_CONTEXT_HANDLER
723     debug_logger->element("contexthandler.endField");
724 #endif
725     startCharacterGroup();
726     if (isForwardEvents())
727         mpStream->text(sFieldEnd, 1);
728     endCharacterGroup();
729 }
730 
ftnednref()731 void OOXMLFastContextHandler::ftnednref()
732 {
733 #ifdef DEBUG_CONTEXT_HANDLER
734     debug_logger->element("contexthandler.ftnednref");
735 #endif
736     if (isForwardEvents())
737         mpStream->utext(sFtnEdnRef, 1);
738 }
739 
ftnednsep()740 void OOXMLFastContextHandler::ftnednsep()
741 {
742 #ifdef DEBUG_CONTEXT_HANDLER
743     debug_logger->element("contexthandler.ftnednsep");
744 #endif
745     if (isForwardEvents())
746         mpStream->utext(sFtnEdnSep, 1);
747 }
748 
ftnedncont()749 void OOXMLFastContextHandler::ftnedncont()
750 {
751 #ifdef DEBUG_CONTEXT_HANDLER
752     debug_logger->element("contexthandler.ftnedncont");
753 #endif
754     if (isForwardEvents())
755         mpStream->text(sFtnEdnCont, 1);
756 }
757 
pgNum()758 void OOXMLFastContextHandler::pgNum()
759 {
760 #ifdef DEBUG_CONTEXT_HANDLER
761     debug_logger->element("contexthandler.pgNum");
762 #endif
763     if (isForwardEvents())
764         mpStream->utext((const sal_uInt8*)sPgNum, 1);
765 }
766 
tab()767 void OOXMLFastContextHandler::tab()
768 {
769 #ifdef DEBUG_CONTEXT_HANDLER
770     debug_logger->element("contexthandler.tab");
771 #endif
772     if (isForwardEvents())
773         mpStream->utext((const sal_uInt8*)sTab, 1);
774 }
775 
cr()776 void OOXMLFastContextHandler::cr()
777 {
778 #ifdef DEBUG_CONTEXT_HANDLER
779     debug_logger->element("contexthandler.cr");
780 #endif
781     if (isForwardEvents())
782         mpStream->utext((const sal_uInt8*)sCR, 1);
783 }
784 
noBreakHyphen()785 void OOXMLFastContextHandler::noBreakHyphen()
786 {
787 #ifdef DEBUG_CONTEXT_HANDLER
788     debug_logger->element("contexthandler.noBreakHyphen");
789 #endif
790     if (isForwardEvents())
791         mpStream->utext((const sal_uInt8*)sNoBreakHyphen, 1);
792 }
793 
softHyphen()794 void OOXMLFastContextHandler::softHyphen()
795 {
796 #ifdef DEBUG_CONTEXT_HANDLER
797     debug_logger->element("contexthandler.softHyphen");
798 #endif
799     if (isForwardEvents())
800         mpStream->utext((const sal_uInt8*)sSoftHyphen, 1);
801 }
802 
handleLastParagraphInSection()803 void OOXMLFastContextHandler::handleLastParagraphInSection()
804 {
805 #ifdef DEBUG_CONTEXT_HANDLER
806     debug_logger->element("contexthandler.handleLastParagraphInSection");
807 #endif
808 
809     if (mpParserState->isLastParagraphInSection())
810     {
811         mpParserState->setLastParagraphInSection(false);
812         startSectionGroup();
813     }
814 }
815 
endOfParagraph()816 void OOXMLFastContextHandler::endOfParagraph()
817 {
818 #ifdef DEBUG_CONTEXT_HANDLER
819     debug_logger->element("contexthandler.endOfParagraph");
820 #endif
821     if (! mpParserState->isInCharacterGroup())
822         startCharacterGroup();
823     if (isForwardEvents())
824         mpStream->utext((const sal_uInt8*)sCR, 1);
825 }
826 
text(const::rtl::OUString & sText)827 void OOXMLFastContextHandler::text(const ::rtl::OUString & sText)
828 {
829 #ifdef DEBUG_CONTEXT_HANDLER
830     debug_logger->startElement("contexthandler.text");
831     debug_logger->chars(sText);
832     debug_logger->endElement("contexthandler.text");
833 #endif
834 
835     if (isForwardEvents())
836         mpStream->utext(reinterpret_cast < const sal_uInt8 * >
837                         (sText.getStr()),
838                         sText.getLength());
839 }
840 
propagateCharacterProperties()841 void OOXMLFastContextHandler::propagateCharacterProperties()
842 {
843 #ifdef DEBUG_CONTEXT_HANDLER
844     debug_logger->startElement("contexthandler.propagateCharacterProperties");
845     debug_logger->addTag(toPropertiesTag(getPropertySet()));
846     debug_logger->endElement("contexthandler.propagateCharacterProperties");
847 #endif
848 
849     mpParserState->setCharacterProperties(getPropertySet());
850 }
851 
propagateCharacterPropertiesAsSet(const Id & rId)852 void OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const Id & rId)
853 {
854 #ifdef DEBUG_CONTEXT_HANDLER
855     debug_logger->startElement("contexthandler.propagateCharacterPropertiesAsSet");
856     debug_logger->addTag(toPropertiesTag(getPropertySet()));
857     debug_logger->endElement("contexthandler.propagateCharacterPropertiesAsSet");
858 #endif
859 
860     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
861     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
862 
863     OOXMLProperty::Pointer_t pProp
864         (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
865 
866     pPropertySet->add(pProp);
867     mpParserState->setCharacterProperties(pPropertySet);
868 }
869 
propagatesProperties() const870 bool OOXMLFastContextHandler::propagatesProperties() const
871 {
872     return false;
873 }
874 
propagateCellProperties()875 void OOXMLFastContextHandler::propagateCellProperties()
876 {
877 #ifdef DEBUG_CONTEXT_HANDLER
878     debug_logger->element("contexthandler.propagateCellProperties");
879 #endif
880 
881     mpParserState->setCellProperties(getPropertySet());
882 }
883 
propagateRowProperties()884 void OOXMLFastContextHandler::propagateRowProperties()
885 {
886 #ifdef DEBUG_CONTEXT_HANDLER
887     debug_logger->element("contexthandler.propagateRowProperties");
888 #endif
889 
890     mpParserState->setRowProperties(getPropertySet());
891 }
892 
propagateTableProperties()893 void OOXMLFastContextHandler::propagateTableProperties()
894 {
895     OOXMLPropertySet::Pointer_t pProps = getPropertySet();
896 #ifdef DEBUG_CONTEXT_HANDLER
897     debug_logger->startElement("contexthandler.propagateTableProperties");
898     debug_logger->addTag(toPropertiesTag(pProps));
899     debug_logger->endElement("contexthandler.propagateTableProperties");
900 #endif
901 
902     mpParserState->setTableProperties(pProps);
903 }
904 
sendCellProperties()905 void OOXMLFastContextHandler::sendCellProperties()
906 {
907 #ifdef DEBUG_CONTEXT_HANDLER
908     debug_logger->startElement("contexthandler.sendCellProperties");
909 #endif
910 
911     mpParserState->resolveCellProperties(*mpStream);
912 
913 #ifdef DEBUG_CONTEXT_HANDLER
914     debug_logger->endElement("contexthandler.sendCellProperties");
915 #endif
916 }
917 
sendRowProperties()918 void OOXMLFastContextHandler::sendRowProperties()
919 {
920 #ifdef DEBUG_CONTEXT_HANDLER
921     debug_logger->startElement("contexthandler.sendRowProperties");
922 #endif
923 
924     mpParserState->resolveRowProperties(*mpStream);
925 
926 #ifdef DEBUG_CONTEXT_HANDLER
927     debug_logger->endElement("contexthandler.sendRowProperties");
928 #endif
929 }
930 
sendTableProperties()931 void OOXMLFastContextHandler::sendTableProperties()
932 {
933 #ifdef DEBUG_CONTEXT_HANDLER
934     debug_logger->startElement("contexthandler.sendTableProperties");
935 #endif
936 
937     mpParserState->resolveTableProperties(*mpStream);
938 
939 #ifdef DEBUG_CONTEXT_HANDLER
940     debug_logger->endElement("contexthandler.sendTableProperties");
941 #endif
942 }
943 
clearTableProps()944 void OOXMLFastContextHandler::clearTableProps()
945 {
946 #ifdef DEBUG_CONTEXT_HANDLER
947     debug_logger->element("contexthandler.clearTableProps");
948 #endif
949 
950     mpParserState->setTableProperties(OOXMLPropertySet::Pointer_t
951                                      (new OOXMLPropertySetImpl()));
952 }
953 
sendPropertiesWithId(const Id & rId)954 void OOXMLFastContextHandler::sendPropertiesWithId(const Id & rId)
955 {
956 #ifdef DEBUG_CONTEXT_HANDLER
957     debug_logger->startElement("contexthandler.sendPropertiesWithId");
958     debug_logger->attribute("id", fastTokenToId(rId));
959 #endif
960 
961     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
962     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
963 
964     OOXMLProperty::Pointer_t pProp
965     (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
966 
967     pPropertySet->add(pProp);
968     mpStream->props(pPropertySet);
969 
970 #ifdef DEBUG_CONTEXT_HANDLER
971     debug_logger->addTag(toPropertiesTag(pPropertySet));
972     debug_logger->endElement("contexthandler.sendPropertiesWithId");
973 #endif
974 }
975 
clearProps()976 void OOXMLFastContextHandler::clearProps()
977 {
978 #ifdef DEBUG_CONTEXT_HANDLER
979     debug_logger->element("contexthandler.clearProps");
980 #endif
981 
982     setPropertySet(OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl()));
983 }
984 
setDefaultBooleanValue()985 void OOXMLFastContextHandler::setDefaultBooleanValue()
986 {
987 }
988 
setDefaultIntegerValue()989 void OOXMLFastContextHandler::setDefaultIntegerValue()
990 {
991 }
992 
setDefaultHexValue()993 void OOXMLFastContextHandler::setDefaultHexValue()
994 {
995 }
996 
setDefaultStringValue()997 void OOXMLFastContextHandler::setDefaultStringValue()
998 {
999 }
1000 
setDocument(OOXMLDocument * pDocument)1001 void OOXMLFastContextHandler::setDocument(OOXMLDocument * pDocument)
1002 {
1003     mpParserState->setDocument(pDocument);
1004 }
1005 
getDocument()1006 OOXMLDocument * OOXMLFastContextHandler::getDocument()
1007 {
1008     return mpParserState->getDocument();
1009 }
1010 
setForwardEvents(bool bForwardEvents)1011 void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents)
1012 {
1013 #ifdef DEBUG_CONTEXT_HANDLER
1014     debug_logger->startElement("contexthandler.setForwardEvents");
1015 
1016     if (bForwardEvents)
1017         debug_logger->chars("true");
1018     else
1019         debug_logger->chars("false");
1020 
1021     debug_logger->endElement("contexthandler.setForwardEvents");
1022 #endif
1023 
1024     mpParserState->setForwardEvents(bForwardEvents);
1025 }
1026 
isForwardEvents() const1027 bool OOXMLFastContextHandler::isForwardEvents() const
1028 {
1029     return mpParserState->isForwardEvents();
1030 }
1031 
1032 
setIDForXNoteStream(OOXMLValue::Pointer_t pValue)1033 void OOXMLFastContextHandler::setIDForXNoteStream(OOXMLValue::Pointer_t pValue)
1034 {
1035     mpParserState->getDocument()->setIDForXNoteStream(pValue->getInt());
1036 }
1037 
1038 
resolveFootnote(const sal_Int32 nIDForXNoteStream)1039 void OOXMLFastContextHandler::resolveFootnote(
1040     const sal_Int32 nIDForXNoteStream )
1041 {
1042     mpParserState->getDocument()->resolveFootnote
1043         (*mpStream, 0, nIDForXNoteStream);
1044 }
1045 
resolveEndnote(const sal_Int32 nIDForXNoteStream)1046 void OOXMLFastContextHandler::resolveEndnote(
1047     const sal_Int32 nIDForXNoteStream )
1048 {
1049     mpParserState->getDocument()->resolveEndnote
1050         (*mpStream, 0, nIDForXNoteStream);
1051 }
1052 
resolveComment(const sal_Int32 nIDForXNoteStream)1053 void OOXMLFastContextHandler::resolveComment(
1054     const sal_Int32 nIDForXNoteStream )
1055 {
1056     mpParserState->getDocument()->resolveComment(*mpStream, nIDForXNoteStream);
1057 }
1058 
resolvePicture(const rtl::OUString & rId)1059 void OOXMLFastContextHandler::resolvePicture(const rtl::OUString & rId)
1060 {
1061     mpParserState->getDocument()->resolvePicture(*mpStream, rId);
1062 }
1063 
resolveHeader(const sal_Int32 type,const rtl::OUString & rId)1064 void OOXMLFastContextHandler::resolveHeader
1065 (const sal_Int32 type, const rtl::OUString & rId)
1066 {
1067     mpParserState->getDocument()->resolveHeader(*mpStream, type, rId);
1068 }
1069 
resolveFooter(const sal_Int32 type,const rtl::OUString & rId)1070 void OOXMLFastContextHandler::resolveFooter
1071 (const sal_Int32 type, const rtl::OUString & rId)
1072 {
1073     mpParserState->getDocument()->resolveFooter(*mpStream, type, rId);
1074 }
1075 
resolveOLE(const rtl::OUString & rId)1076 void OOXMLFastContextHandler::resolveOLE(const rtl::OUString & rId)
1077 {
1078     uno::Reference<io::XInputStream> xInputStream
1079         (mpParserState->getDocument()->getInputStreamForId(rId));
1080 
1081     OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream));
1082 
1083     newProperty(NS_ooxml::LN_inputstream, aValue);
1084 }
1085 
getTargetForId(const::rtl::OUString & rId)1086 ::rtl::OUString OOXMLFastContextHandler::getTargetForId
1087 (const ::rtl::OUString & rId)
1088 {
1089     return mpParserState->getDocument()->getTargetForId(rId);
1090 }
1091 
resolvePropertySetAttrs()1092 void OOXMLFastContextHandler::resolvePropertySetAttrs()
1093 {
1094 }
1095 
sendPropertyToParent()1096 void OOXMLFastContextHandler::sendPropertyToParent()
1097 {
1098 #ifdef DEBUG_CONTEXT_HANDLER
1099     debug_logger->startElement("contexthandler.sendPropertyToParent");
1100 #endif
1101 
1102     if (mpParent != NULL)
1103     {
1104         OOXMLPropertySet::Pointer_t pProps(mpParent->getPropertySet());
1105 
1106         if (pProps.get() != NULL)
1107         {
1108             OOXMLProperty::Pointer_t
1109                 pProp(new OOXMLPropertyImpl(mId, getValue(),
1110                                             OOXMLPropertyImpl::SPRM));
1111             pProps->add(pProp);
1112 
1113 #ifdef DEBUG_CONTEXT_HANDLER
1114             debug_logger->addTag(toPropertiesTag(pProps));
1115 #endif
1116         }
1117     }
1118 
1119 #ifdef DEBUG_CONTEXT_HANDLER
1120     debug_logger->endElement("contexthandler.sendPropertyToParent");
1121 #endif
1122 }
1123 
sendPropertiesToParent()1124 void OOXMLFastContextHandler::sendPropertiesToParent()
1125 {
1126 #ifdef DEBUG_CONTEXT_HANDLER
1127     debug_logger->startElement("contexthandler.sendPropertiesToParent");
1128 #endif
1129     if (mpParent != NULL)
1130     {
1131         OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet());
1132 
1133         if (pParentProps.get() != NULL)
1134         {
1135             OOXMLPropertySet::Pointer_t pProps(getPropertySet());
1136 
1137             if (pProps.get() != NULL)
1138             {
1139                 OOXMLValue::Pointer_t pValue
1140                 (new OOXMLPropertySetValue(getPropertySet()));
1141 
1142                 OOXMLProperty::Pointer_t pProp
1143                 (new OOXMLPropertyImpl(getId(), pValue, OOXMLPropertyImpl::SPRM));
1144 
1145                 pParentProps->add(pProp);
1146             }
1147         }
1148     }
1149 #ifdef DEBUG_CONTEXT_HANDLER
1150     debug_logger->endElement("contexthandler.sendPropertiesToParent");
1151 #endif
1152 }
1153 
1154 uno::Reference< uno::XComponentContext >
getComponentContext()1155 OOXMLFastContextHandler::getComponentContext()
1156 {
1157     return m_xContext;
1158 }
1159 
1160 /*
1161   class OOXMLFastContextHandlerStream
1162  */
1163 
OOXMLFastContextHandlerStream(OOXMLFastContextHandler * pContext)1164 OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
1165 (OOXMLFastContextHandler * pContext)
1166 : OOXMLFastContextHandler(pContext),
1167   mpPropertySetAttrs(new OOXMLPropertySetImpl())
1168 {
1169 }
1170 
~OOXMLFastContextHandlerStream()1171 OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
1172 {
1173 }
1174 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)1175 void OOXMLFastContextHandlerStream::newProperty(const Id & rId,
1176                                                 OOXMLValue::Pointer_t pVal)
1177 {
1178     if (rId != 0x0)
1179     {
1180         OOXMLPropertyImpl::Pointer_t pProperty
1181             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
1182 
1183         mpPropertySetAttrs->add(pProperty);
1184     }
1185 }
1186 
sendProperty(Id nId)1187 void OOXMLFastContextHandlerStream::sendProperty(Id nId)
1188 {
1189 #ifdef DEBUG_CONTEXT_HANDLER
1190     debug_logger->startElement("contexthandler.sendProperty");
1191     debug_logger->attribute("id", (*QNameToString::Instance())(nId));
1192     debug_logger->chars(xmlify(getPropertySetAttrs()->toString()));
1193     debug_logger->endElement("contexthandler.sendProperty");
1194 #endif
1195 
1196     OOXMLPropertySetEntryToString aHandler(nId);
1197     getPropertySetAttrs()->resolve(aHandler);
1198     const ::rtl::OUString & sText = aHandler.getString();
1199     mpStream->utext(reinterpret_cast < const sal_uInt8 * >
1200                     (sText.getStr()),
1201                     sText.getLength());
1202 }
1203 
1204 OOXMLPropertySet::Pointer_t
getPropertySetAttrs() const1205 OOXMLFastContextHandlerStream::getPropertySetAttrs() const
1206 {
1207     return mpPropertySetAttrs;
1208 }
1209 
resolvePropertySetAttrs()1210 void OOXMLFastContextHandlerStream::resolvePropertySetAttrs()
1211 {
1212 #ifdef DEBUG_CONTEXT_HANDLER
1213         debug_logger->startElement("contexthandler.resolvePropertySetAttrs");
1214         debug_logger->chars(mpPropertySetAttrs->toString());
1215         debug_logger->endElement("contexthandler.resolvePropertySetAttrs");
1216 #endif
1217     mpStream->props(mpPropertySetAttrs);
1218 }
1219 
getPropertySet() const1220 OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerStream::getPropertySet()
1221     const
1222 {
1223     return getPropertySetAttrs();
1224 }
1225 
handleHyperlink()1226 void OOXMLFastContextHandlerStream::handleHyperlink()
1227 {
1228     OOXMLHyperlinkHandler aHyperlinkHandler(this);
1229     getPropertySetAttrs()->resolve(aHyperlinkHandler);
1230 }
1231 
1232 /*
1233   class OOXMLFastContextHandlerProperties
1234  */
OOXMLFastContextHandlerProperties(OOXMLFastContextHandler * pContext)1235 OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties
1236 (OOXMLFastContextHandler * pContext)
1237 : OOXMLFastContextHandler(pContext), mpPropertySet(new OOXMLPropertySetImpl()),
1238   mbResolve(false)
1239 {
1240     if (pContext->getResource() == STREAM)
1241         mbResolve = true;
1242 }
1243 
~OOXMLFastContextHandlerProperties()1244 OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties()
1245 {
1246 }
1247 
lcl_endFastElement(sal_Int32 Element)1248 void OOXMLFastContextHandlerProperties::lcl_endFastElement
1249 (sal_Int32 Element)
1250     throw (uno::RuntimeException, xml::sax::SAXException)
1251 {
1252     endAction(Element);
1253 
1254     if (mbResolve)
1255     {
1256         if (isForwardEvents())
1257         {
1258             mpStream->props(mpPropertySet);
1259         }
1260     }
1261     else
1262     {
1263         sendPropertiesToParent();
1264     }
1265 }
1266 
getValue() const1267 OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const
1268 {
1269     return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet));
1270 }
1271 
1272 #ifdef DEBUG
toTag() const1273 XMLTag::Pointer_t OOXMLFastContextHandlerProperties::toTag() const
1274 {
1275     XMLTag::Pointer_t pTag(OOXMLFastContextHandler::toTag());
1276     pTag->addAttr("resolve", mbResolve ? "resolve" : "noResolve");
1277 
1278     return pTag;
1279 }
1280 #endif
1281 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)1282 void OOXMLFastContextHandlerProperties::newProperty
1283 (const Id & rId, OOXMLValue::Pointer_t pVal)
1284 {
1285     if (rId != 0x0)
1286     {
1287         OOXMLPropertyImpl::Pointer_t pProperty
1288             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
1289 
1290         mpPropertySet->add(pProperty);
1291     }
1292 }
1293 
handleXNotes()1294 void OOXMLFastContextHandlerProperties::handleXNotes()
1295 {
1296     switch (mnToken)
1297     {
1298     case NS_wordprocessingml|OOXML_footnoteReference:
1299         {
1300             OOXMLFootnoteHandler aFootnoteHandler(this);
1301             mpPropertySet->resolve(aFootnoteHandler);
1302         }
1303         break;
1304     case NS_wordprocessingml|OOXML_endnoteReference:
1305         {
1306             OOXMLEndnoteHandler aEndnoteHandler(this);
1307             mpPropertySet->resolve(aEndnoteHandler);
1308         }
1309         break;
1310     default:
1311         break;
1312     }
1313 }
1314 
handleHdrFtr()1315 void OOXMLFastContextHandlerProperties::handleHdrFtr()
1316 {
1317     switch (mnToken)
1318     {
1319     case NS_wordprocessingml|OOXML_footerReference:
1320         {
1321             OOXMLFooterHandler aFooterHandler(this);
1322             mpPropertySet->resolve(aFooterHandler);
1323         }
1324         break;
1325     case NS_wordprocessingml|OOXML_headerReference:
1326         {
1327             OOXMLHeaderHandler aHeaderHandler(this);
1328             mpPropertySet->resolve(aHeaderHandler);
1329         }
1330         break;
1331     default:
1332         break;
1333     }
1334 }
1335 
handleComment()1336 void OOXMLFastContextHandlerProperties::handleComment()
1337 {
1338 #ifdef DEBUG_CONTEXT_HANDLER
1339     debug_logger->element("handleComment");
1340 #endif
1341 
1342     OOXMLCommentHandler aCommentHandler(this);
1343     getPropertySet()->resolve(aCommentHandler);
1344 }
1345 
handlePicture()1346 void OOXMLFastContextHandlerProperties::handlePicture()
1347 {
1348 #ifdef DEBUG_CONTEXT_HANDLER
1349     debug_logger->element("handlePicture");
1350 #endif
1351 
1352     OOXMLPictureHandler aPictureHandler(this);
1353     getPropertySet()->resolve(aPictureHandler);
1354 }
1355 
handleBreak()1356 void OOXMLFastContextHandlerProperties::handleBreak()
1357 {
1358 #ifdef DEBUG_CONTEXT_HANDLER
1359     debug_logger->element("handleBreak");
1360 #endif
1361 
1362     OOXMLBreakHandler aBreakHandler(*mpStream, this);
1363     getPropertySet()->resolve(aBreakHandler);
1364 }
1365 
handleOLE()1366 void OOXMLFastContextHandlerProperties::handleOLE()
1367 {
1368 #ifdef DEBUG_CONTEXT_HANDLER
1369     debug_logger->element("handleOLE");
1370 #endif
1371 
1372     OOXMLOLEHandler aOLEHandler(this);
1373     getPropertySet()->resolve(aOLEHandler);
1374 }
1375 
setParent(OOXMLFastContextHandler * pParent)1376 void OOXMLFastContextHandlerProperties::setParent
1377 (OOXMLFastContextHandler * pParent)
1378 {
1379 #ifdef DEBUG_CONTEXT_HANDLER
1380     debug_logger->startElement("setParent");
1381     debug_logger->chars("OOXMLFastContextHandlerProperties");
1382     debug_logger->endElement("setParent");
1383 #endif
1384 
1385     OOXMLFastContextHandler::setParent(pParent);
1386 
1387     if (mpParent->getResource() == STREAM)
1388         mbResolve = true;
1389 }
1390 
setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet)1391 void OOXMLFastContextHandlerProperties::setPropertySet
1392 (OOXMLPropertySet::Pointer_t pPropertySet)
1393 {
1394     if (pPropertySet.get() != NULL)
1395         mpPropertySet = pPropertySet;
1396 }
1397 
1398 OOXMLPropertySet::Pointer_t
getPropertySet() const1399 OOXMLFastContextHandlerProperties::getPropertySet() const
1400 {
1401     return mpPropertySet;
1402 }
1403 
1404 /*
1405  * class OOXMLFasContextHandlerPropertyTable
1406  */
1407 
OOXMLFastContextHandlerPropertyTable(OOXMLFastContextHandler * pContext)1408 OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable
1409 (OOXMLFastContextHandler * pContext)
1410 : OOXMLFastContextHandlerProperties(pContext)
1411 {
1412 }
1413 
~OOXMLFastContextHandlerPropertyTable()1414 OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable()
1415 {
1416 }
1417 
lcl_endFastElement(sal_Int32 Element)1418 void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement
1419 (sal_Int32 Element)
1420     throw (uno::RuntimeException, xml::sax::SAXException)
1421 {
1422     OOXMLPropertySet::Pointer_t pPropSet(mpPropertySet->clone());
1423     OOXMLTableImpl::ValuePointer_t pTmpVal
1424         (new OOXMLPropertySetValue(pPropSet));
1425 
1426     mTable.add(pTmpVal);
1427 
1428     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1429 
1430 #ifdef DEBUG_PROPERTIES
1431     debug_logger->startElement("table");
1432     debug_logger->attribute("id", (*QNameToString::Instance())(mId));
1433     debug_logger->endElement("table");
1434 #endif
1435 
1436     mpStream->table(mId, pTable);
1437 
1438     endAction(Element);
1439 }
1440 
1441 /*
1442  class OOXMLFastContextHandlerValue
1443 */
1444 
OOXMLFastContextHandlerValue(OOXMLFastContextHandler * pContext)1445 OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue
1446 (OOXMLFastContextHandler * pContext)
1447 : OOXMLFastContextHandler(pContext)
1448 {
1449 }
1450 
~OOXMLFastContextHandlerValue()1451 OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue()
1452 {
1453 }
1454 
setValue(OOXMLValue::Pointer_t pValue)1455 void OOXMLFastContextHandlerValue::setValue(OOXMLValue::Pointer_t pValue)
1456 {
1457 #ifdef DEBUG_CONTEXT_HANDLER
1458     debug_logger->startElement("contexthandler.setValue");
1459     debug_logger->attribute("value", pValue->toString());
1460 #endif
1461 
1462     mpValue = pValue;
1463 
1464 #ifdef DEBUG_CONTEXT_HANDLER
1465     debug_logger->endElement("contexthandler.setValue");
1466 #endif
1467 }
1468 
getValue() const1469 OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const
1470 {
1471     return mpValue;
1472 }
1473 
lcl_endFastElement(sal_Int32 Element)1474 void OOXMLFastContextHandlerValue::lcl_endFastElement
1475 (sal_Int32 Element)
1476 throw (uno::RuntimeException, xml::sax::SAXException)
1477 {
1478     sendPropertyToParent();
1479 
1480     endAction(Element);
1481 }
1482 
setDefaultBooleanValue()1483 void OOXMLFastContextHandlerValue::setDefaultBooleanValue()
1484 {
1485 #ifdef DEBUG_CONTEXT_HANDLER
1486     debug_logger->element("setDefaultBooleanValue");
1487 #endif
1488 
1489     if (mpValue.get() == NULL)
1490     {
1491         OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(true));
1492         setValue(pValue);
1493     }
1494 }
1495 
setDefaultIntegerValue()1496 void OOXMLFastContextHandlerValue::setDefaultIntegerValue()
1497 {
1498 #ifdef DEBUG_CONTEXT_HANDLER
1499     debug_logger->element("setDefaultIntegerValue");
1500 #endif
1501 
1502     if (mpValue.get() == NULL)
1503     {
1504         OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(0));
1505         setValue(pValue);
1506     }
1507 }
1508 
setDefaultHexValue()1509 void OOXMLFastContextHandlerValue::setDefaultHexValue()
1510 {
1511 #ifdef DEBUG_CONTEXT_HANDLER
1512     debug_logger->element("setDefaultHexValue");
1513 #endif
1514 
1515     if (mpValue.get() == NULL)
1516     {
1517         OOXMLValue::Pointer_t pValue(new OOXMLHexValue(0));
1518         setValue(pValue);
1519     }
1520 }
1521 
setDefaultStringValue()1522 void OOXMLFastContextHandlerValue::setDefaultStringValue()
1523 {
1524 #ifdef DEBUG_CONTEXT_HANDLER
1525     debug_logger->element("setDefaultStringValue");
1526 #endif
1527 
1528     if (mpValue.get() == NULL)
1529     {
1530         OOXMLValue::Pointer_t pValue(new OOXMLStringValue(::rtl::OUString()));
1531         setValue(pValue);
1532     }
1533 }
1534 /*
1535   class OOXMLFastContextHandlerTable
1536 */
1537 
OOXMLFastContextHandlerTable(OOXMLFastContextHandler * pContext)1538 OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable
1539 (OOXMLFastContextHandler * pContext)
1540 : OOXMLFastContextHandler(pContext)
1541 {
1542 }
1543 
~OOXMLFastContextHandlerTable()1544 OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable()
1545 {
1546 }
1547 
1548 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1549 OOXMLFastContextHandlerTable::createFastChildContext
1550 (sal_Int32 Element,
1551  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1552     throw (uno::RuntimeException, xml::sax::SAXException)
1553 {
1554     addCurrentChild();
1555 
1556     mCurrentChild.set
1557         (OOXMLFastContextHandler::createFastChildContext(Element, Attribs));
1558 
1559     return mCurrentChild;
1560 }
1561 
lcl_endFastElement(sal_Int32)1562 void OOXMLFastContextHandlerTable::lcl_endFastElement
1563 (sal_Int32 /*Element*/)
1564     throw (uno::RuntimeException, xml::sax::SAXException)
1565 {
1566     addCurrentChild();
1567 
1568     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1569     if (isForwardEvents() && mId != 0x0)
1570     {
1571 #ifdef DEBUG_PROPERTIES
1572         debug_logger->startElement("table");
1573         string str = (*QNameToString::Instance())(mId);
1574         debug_logger->attribute("id", str);
1575         debug_logger->endElement("table");
1576 #endif
1577 
1578         mpStream->table(mId, pTable);
1579     }
1580 }
1581 
addCurrentChild()1582 void OOXMLFastContextHandlerTable::addCurrentChild()
1583 {
1584     OOXMLFastContextHandler * pHandler = mCurrentChild.getPointer();
1585     if ( pHandler != NULL)
1586     {
1587         OOXMLValue::Pointer_t pValue(pHandler->getValue());
1588 
1589         if (pValue.get() != NULL)
1590         {
1591             OOXMLTableImpl::ValuePointer_t pTmpVal(pValue->clone());
1592             mTable.add(pTmpVal);
1593         }
1594     }
1595 }
1596 
newPropertySet(OOXMLPropertySet::Pointer_t)1597 void OOXMLFastContextHandlerTable::newPropertySet
1598 (OOXMLPropertySet::Pointer_t /*pPropertySet*/)
1599 {
1600 
1601 }
1602 
1603 /*
1604   class OOXMLFastContextHandlerXNote
1605  */
1606 
OOXMLFastContextHandlerXNote(OOXMLFastContextHandler * pContext)1607 OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote
1608     ( OOXMLFastContextHandler * pContext )
1609     : OOXMLFastContextHandlerProperties( pContext )
1610     , mbForwardEventsSaved( false )
1611     , mnMyXNoteId( -1 )
1612 {
1613 }
1614 
~OOXMLFastContextHandlerXNote()1615 OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote()
1616 {
1617 }
1618 
lcl_startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> &)1619 void OOXMLFastContextHandlerXNote::lcl_startFastElement
1620 (sal_Int32 Element,
1621  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1622     throw (uno::RuntimeException, xml::sax::SAXException)
1623 {
1624     mbForwardEventsSaved = isForwardEvents();
1625 
1626     if ( mnMyXNoteId == mpParserState->getDocument()->getIDForXNoteStream() )
1627         setForwardEvents(true);
1628     else
1629         setForwardEvents(false);
1630 
1631     startAction(Element);
1632 }
1633 
lcl_endFastElement(sal_Int32 Element)1634 void OOXMLFastContextHandlerXNote::lcl_endFastElement
1635 (sal_Int32 Element)
1636     throw (uno::RuntimeException, xml::sax::SAXException)
1637 {
1638     // handle properties by calling parent class' method
1639     OOXMLFastContextHandlerProperties::lcl_endFastElement( Element );
1640 
1641     setForwardEvents(mbForwardEventsSaved);
1642 }
1643 
checkId(OOXMLValue::Pointer_t pValue)1644 void OOXMLFastContextHandlerXNote::checkId(OOXMLValue::Pointer_t pValue)
1645 {
1646 #ifdef DEBUG_CONTEXT_HANDLER
1647     debug_logger->startElement("checkId");
1648     debug_logger->attribute("myId", pValue->getInt());
1649     debug_logger->attribute("id", mpParserState->getDocument()->getXNoteId());
1650     debug_logger->endElement("checkId");
1651 #endif
1652 
1653     mnMyXNoteId = pValue->getInt();
1654 }
1655 
1656 /*
1657   class OOXMLFastContextHandlerTextTableCell
1658  */
1659 
OOXMLFastContextHandlerTextTableCell(OOXMLFastContextHandler * pContext)1660 OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell
1661 (OOXMLFastContextHandler * pContext)
1662 : OOXMLFastContextHandler(pContext)
1663 {
1664 }
1665 
~OOXMLFastContextHandlerTextTableCell()1666 OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
1667 {
1668 }
1669 
startCell()1670 void OOXMLFastContextHandlerTextTableCell::startCell()
1671 {
1672 }
1673 
endCell()1674 void OOXMLFastContextHandlerTextTableCell::endCell()
1675 {
1676     if (isForwardEvents())
1677     {
1678         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1679         {
1680             OOXMLValue::Pointer_t pVal
1681                 (new OOXMLIntegerValue(mnTableDepth));
1682             OOXMLProperty::Pointer_t pProp
1683                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
1684             pProps->add(pProp);
1685         }
1686         {
1687             OOXMLValue::Pointer_t pVal
1688                 (new OOXMLIntegerValue(1));
1689             OOXMLProperty::Pointer_t pProp
1690                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
1691             pProps->add(pProp);
1692         }
1693         {
1694             OOXMLValue::Pointer_t pVal
1695                 (new OOXMLBooleanValue(mnTableDepth > 0));
1696             OOXMLProperty::Pointer_t pProp
1697                 (new OOXMLPropertyImpl(NS_sprm::LN_PCell, pVal, OOXMLPropertyImpl::SPRM));
1698             pProps->add(pProp);
1699         }
1700 
1701 #ifdef DEBUG_PROPERTIES
1702         debug_logger->startElement("endcell");
1703         debug_logger->addTag(toPropertiesTag
1704                              (OOXMLPropertySet::Pointer_t(pProps->clone())));
1705         debug_logger->endElement("endcell");
1706 #endif
1707         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1708     }
1709 }
1710 
1711 /*
1712   class OOXMLFastContextHandlerTextTableRow
1713  */
1714 
OOXMLFastContextHandlerTextTableRow(OOXMLFastContextHandler * pContext)1715 OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow
1716 (OOXMLFastContextHandler * pContext)
1717 : OOXMLFastContextHandler(pContext)
1718 {
1719 }
1720 
~OOXMLFastContextHandlerTextTableRow()1721 OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow()
1722 {
1723 }
1724 
startRow()1725 void OOXMLFastContextHandlerTextTableRow::startRow()
1726 {
1727 }
1728 
endRow()1729 void OOXMLFastContextHandlerTextTableRow::endRow()
1730 {
1731     startParagraphGroup();
1732 
1733     if (isForwardEvents())
1734     {
1735         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1736         {
1737             OOXMLValue::Pointer_t pVal
1738                 (new OOXMLIntegerValue(mnTableDepth));
1739             OOXMLProperty::Pointer_t pProp
1740                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
1741             pProps->add(pProp);
1742         }
1743         {
1744             OOXMLValue::Pointer_t pVal
1745                 (new OOXMLIntegerValue(1));
1746             OOXMLProperty::Pointer_t pProp
1747                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
1748             pProps->add(pProp);
1749         }
1750         {
1751             OOXMLValue::Pointer_t pVal
1752                 (new OOXMLIntegerValue(1));
1753             OOXMLProperty::Pointer_t pProp
1754                 (new OOXMLPropertyImpl(NS_sprm::LN_PRow, pVal, OOXMLPropertyImpl::SPRM));
1755             pProps->add(pProp);
1756         }
1757 
1758 #ifdef DEBUG_PROPERTIES
1759         debug_logger->startElement("endrow");
1760         debug_logger->addTag(toPropertiesTag
1761                              (OOXMLPropertySet::Pointer_t(pProps->clone())));
1762         debug_logger->endElement("endrow");
1763 #endif
1764 
1765         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1766     }
1767 
1768     startCharacterGroup();
1769 
1770     if (isForwardEvents())
1771         mpStream->utext(s0xd, 1);
1772 
1773     endCharacterGroup();
1774     endParagraphGroup();
1775 }
1776 
1777 /*
1778   class OOXMLFastContextHandlerTextTable
1779  */
1780 
OOXMLFastContextHandlerTextTable(OOXMLFastContextHandler * pContext)1781 OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable
1782 (OOXMLFastContextHandler * pContext)
1783 : OOXMLFastContextHandler(pContext)
1784 {
1785 }
1786 
~OOXMLFastContextHandlerTextTable()1787 OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable()
1788 {
1789     clearTableProps();
1790 }
1791 
lcl_startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> &)1792 void OOXMLFastContextHandlerTextTable::lcl_startFastElement
1793 (sal_Int32 Element,
1794  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1795     throw (uno::RuntimeException, xml::sax::SAXException)
1796 {
1797     mpParserState->startTable();
1798     mnTableDepth++;
1799 
1800     boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
1801     {
1802         OOXMLValue::Pointer_t pVal
1803             (new OOXMLIntegerValue(mnTableDepth));
1804         OOXMLProperty::Pointer_t pProp
1805             (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart, pVal, OOXMLPropertyImpl::SPRM));
1806         pProps->add(pProp);
1807     }
1808     mpParserState->setCharacterProperties(pProps);
1809 
1810     startAction(Element);
1811 }
1812 
lcl_endFastElement(sal_Int32 Element)1813 void OOXMLFastContextHandlerTextTable::lcl_endFastElement
1814 (sal_Int32 Element)
1815     throw (uno::RuntimeException, xml::sax::SAXException)
1816 {
1817     endAction(Element);
1818 
1819     mnTableDepth--;
1820     mpParserState->endTable();
1821 }
1822 
1823 /*
1824   class OOXMLFastContextHandlerShape
1825  */
1826 
OOXMLFastContextHandlerShape(OOXMLFastContextHandler * pContext)1827 OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
1828 (OOXMLFastContextHandler * pContext)
1829 : OOXMLFastContextHandlerProperties(pContext), m_bShapeSent( false ),
1830     m_bShapeStarted(false)
1831 {
1832     uno::Reference<uno::XComponentContext> xContext(getComponentContext());
1833     if (xContext.is())
1834     {
1835         uno::Reference<XMultiComponentFactory> rServiceManager
1836             (xContext->getServiceManager());
1837 
1838         mrShapeContext.set
1839             (rServiceManager->
1840               createInstanceWithContext
1841               (::rtl::OUString
1842                (RTL_CONSTASCII_USTRINGPARAM
1843                 ("com.sun.star.xml.sax.FastShapeContextHandler")), xContext),
1844               uno::UNO_QUERY);
1845 
1846         if (mrShapeContext.is())
1847         {
1848             mrShapeContext->setModel(getDocument()->getModel());
1849             mrShapeContext->setDrawPage(getDocument()->getDrawPage());
1850             mrShapeContext->setInputStream(getDocument()->getStorageStream());
1851 
1852 #ifdef DEBUG_CONTEXT_HANDLER
1853             debug_logger->startElement("setRelationFragmentPath");
1854             debug_logger->attribute("path", mpParserState->getTarget());
1855             debug_logger->endElement("setRelationFragmentPath");
1856 #endif
1857             mrShapeContext->setRelationFragmentPath
1858                 (mpParserState->getTarget());
1859         }
1860 #ifdef DEBUG_CONTEXT_HANDLER
1861         else
1862         {
1863             debug_logger->startElement("error");
1864             debug_logger->chars("failed to get shape handler");
1865             debug_logger->endElement("error");
1866         }
1867 #endif
1868     }
1869 }
1870 
~OOXMLFastContextHandlerShape()1871 OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape()
1872 {
1873 }
1874 
lcl_startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1875 void OOXMLFastContextHandlerShape::lcl_startFastElement
1876 (sal_Int32 Element,
1877  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1878     throw (uno::RuntimeException, xml::sax::SAXException)
1879 {
1880     startAction(Element);
1881 
1882     if (mrShapeContext.is())
1883     {
1884         mrShapeContext->startFastElement(Element, Attribs);
1885     }
1886 }
1887 
startUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1888 void SAL_CALL OOXMLFastContextHandlerShape::startUnknownElement
1889 (const ::rtl::OUString & Namespace,
1890  const ::rtl::OUString & Name,
1891  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1892     throw (uno::RuntimeException, xml::sax::SAXException)
1893 {
1894     if (mrShapeContext.is())
1895         mrShapeContext->startUnknownElement(Namespace, Name, Attribs);
1896 }
1897 
setToken(Token_t nToken)1898 void OOXMLFastContextHandlerShape::setToken(Token_t nToken)
1899 {
1900     OOXMLFastContextHandler::setToken(nToken);
1901 
1902     if (mrShapeContext.is())
1903         mrShapeContext->setStartToken(nToken);
1904 }
1905 
sendShape(Token_t Element)1906 void OOXMLFastContextHandlerShape::sendShape( Token_t Element )
1907 {
1908     if ( mrShapeContext.is() && !m_bShapeSent )
1909     {
1910         uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape());
1911         if (xShape.is())
1912         {
1913             OOXMLValue::Pointer_t
1914                 pValue(new OOXMLShapeValue(xShape));
1915             newProperty(NS_ooxml::LN_shape, pValue);
1916             m_bShapeSent = true;
1917 
1918             bool bIsPicture = Element == ( NS_picture | OOXML_pic );
1919 
1920             // Notify the dmapper that the shape is ready to use
1921             if ( !bIsPicture )
1922             {
1923                 mpStream->startShape( xShape );
1924                 m_bShapeStarted = true;
1925             }
1926         }
1927     }
1928 }
1929 
lcl_endFastElement(sal_Int32 Element)1930 void OOXMLFastContextHandlerShape::lcl_endFastElement
1931 (sal_Int32 Element)
1932     throw (uno::RuntimeException, xml::sax::SAXException)
1933 {
1934     if (mrShapeContext.is())
1935     {
1936         mrShapeContext->endFastElement(Element);
1937         sendShape( Element );
1938     }
1939 
1940     OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
1941 
1942     // Ending the shape should be the last thing to do
1943     bool bIsPicture = Element == ( NS_picture | OOXML_pic );
1944     if ( !bIsPicture && m_bShapeStarted)
1945         mpStream->endShape( );
1946 }
1947 
endUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name)1948 void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement
1949 (const ::rtl::OUString & Namespace,
1950  const ::rtl::OUString & Name)
1951     throw (uno::RuntimeException, xml::sax::SAXException)
1952 {
1953     if (mrShapeContext.is())
1954         mrShapeContext->endUnknownElement(Namespace, Name);
1955 }
1956 
1957 uno::Reference< xml::sax::XFastContextHandler >
lcl_createFastChildContext(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1958 OOXMLFastContextHandlerShape::lcl_createFastChildContext
1959 (sal_Int32 Element,
1960  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1961     throw (uno::RuntimeException, xml::sax::SAXException)
1962 {
1963     uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
1964 
1965     sal_uInt32 nNamespace = Element & 0xffff0000;
1966 
1967     switch (nNamespace)
1968     {
1969         case NS_wordprocessingml:
1970         case NS_vml_wordprocessingDrawing:
1971         case NS_office:
1972             xContextHandler.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
1973             break;
1974         default:
1975             if (mrShapeContext.is())
1976             {
1977                 uno::Reference<XFastContextHandler> pChildContext =
1978                 mrShapeContext->createFastChildContext(Element, Attribs);
1979 
1980                 OOXMLFastContextHandlerWrapper * pWrapper =
1981                 new OOXMLFastContextHandlerWrapper(this, pChildContext);
1982 
1983                 pWrapper->addNamespace(NS_wordprocessingml);
1984                 pWrapper->addNamespace(NS_vml_wordprocessingDrawing);
1985                 pWrapper->addNamespace(NS_office);
1986                 pWrapper->addToken( NS_vml|OOXML_textbox );
1987 
1988                 xContextHandler.set(pWrapper);
1989             }
1990             else
1991                 xContextHandler.set(this);
1992             break;
1993     }
1994 
1995 
1996     return xContextHandler;
1997 }
1998 
1999 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2000 OOXMLFastContextHandlerShape::createUnknownChildContext
2001 (const ::rtl::OUString & Namespace,
2002  const ::rtl::OUString & Name,
2003  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2004     throw (uno::RuntimeException, xml::sax::SAXException)
2005 {
2006     uno::Reference< xml::sax::XFastContextHandler > xResult;
2007 
2008     if (mrShapeContext.is())
2009         xResult.set(mrShapeContext->createUnknownChildContext
2010             (Namespace, Name, Attribs));
2011 
2012     return xResult;
2013 }
2014 
lcl_characters(const::rtl::OUString & aChars)2015 void OOXMLFastContextHandlerShape::lcl_characters
2016 (const ::rtl::OUString & aChars)
2017     throw (uno::RuntimeException, xml::sax::SAXException)
2018 {
2019     if (mrShapeContext.is())
2020         mrShapeContext->characters(aChars);
2021 }
2022 
2023 /*
2024   class OOXMLFastContextHandlerWrapper
2025 */
2026 
OOXMLFastContextHandlerWrapper(OOXMLFastContextHandler * pParent,uno::Reference<XFastContextHandler> xContext)2027 OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper
2028 (OOXMLFastContextHandler * pParent,
2029  uno::Reference<XFastContextHandler> xContext)
2030 : OOXMLFastContextHandler(pParent), mxContext(xContext)
2031 {
2032     if (pParent != NULL)
2033     {
2034         setId(pParent->getId());
2035         setToken(pParent->getToken());
2036         setPropertySet(pParent->getPropertySet());
2037     }
2038 }
2039 
~OOXMLFastContextHandlerWrapper()2040 OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper()
2041 {
2042 }
2043 
startUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2044 void SAL_CALL OOXMLFastContextHandlerWrapper::startUnknownElement
2045 (const ::rtl::OUString & Namespace,
2046  const ::rtl::OUString & Name,
2047  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2048     throw (uno::RuntimeException, xml::sax::SAXException)
2049 {
2050     if (mxContext.is())
2051         mxContext->startUnknownElement(Namespace, Name, Attribs);
2052 }
2053 
endUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name)2054 void SAL_CALL OOXMLFastContextHandlerWrapper::endUnknownElement
2055 (const ::rtl::OUString & Namespace,
2056  const ::rtl::OUString & Name)
2057     throw (uno::RuntimeException, xml::sax::SAXException)
2058 {
2059     if (mxContext.is())
2060         mxContext->endUnknownElement(Namespace, Name);
2061 }
2062 
2063 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2064 OOXMLFastContextHandlerWrapper::createUnknownChildContext
2065 (const ::rtl::OUString & Namespace,
2066  const ::rtl::OUString & Name,
2067  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2068     throw (uno::RuntimeException, xml::sax::SAXException)
2069 {
2070     uno::Reference< xml::sax::XFastContextHandler > xResult;
2071 
2072     if (mxContext.is())
2073         xResult = mxContext->createUnknownChildContext
2074             (Namespace, Name, Attribs);
2075     else
2076         xResult.set(this);
2077 
2078     return xResult;
2079 }
2080 
attributes(const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2081 void OOXMLFastContextHandlerWrapper::attributes
2082 (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2083 throw (uno::RuntimeException, xml::sax::SAXException)
2084 {
2085     if (mxContext.is())
2086     {
2087         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2088         if (pHandler != NULL)
2089             pHandler->attributes(Attribs);
2090     }
2091 }
2092 
2093 OOXMLFastContextHandler::ResourceEnum_t
getResource() const2094 OOXMLFastContextHandlerWrapper::getResource() const
2095 {
2096     return UNKNOWN;
2097 }
2098 
addNamespace(const Id & nId)2099 void OOXMLFastContextHandlerWrapper::addNamespace(const Id & nId)
2100 {
2101     mMyNamespaces.insert(nId);
2102 }
2103 
addToken(Token_t Token)2104 void OOXMLFastContextHandlerWrapper::addToken( Token_t Token )
2105 {
2106     mMyTokens.insert( Token );
2107 }
2108 
lcl_startFastElement(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2109 void OOXMLFastContextHandlerWrapper::lcl_startFastElement
2110 (sal_Int32 Element,
2111  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2112     throw (uno::RuntimeException, xml::sax::SAXException)
2113 {
2114     if (mxContext.is())
2115         mxContext->startFastElement(Element, Attribs);
2116 }
2117 
lcl_endFastElement(sal_Int32 Element)2118 void OOXMLFastContextHandlerWrapper::lcl_endFastElement
2119 (sal_Int32 Element)
2120     throw (uno::RuntimeException, xml::sax::SAXException)
2121 {
2122     if (mxContext.is())
2123         mxContext->endFastElement(Element);
2124 }
2125 
2126 uno::Reference< xml::sax::XFastContextHandler >
lcl_createFastChildContext(sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2127 OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
2128 (sal_Int32 Element,
2129  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2130     throw (uno::RuntimeException, xml::sax::SAXException)
2131 {
2132     uno::Reference< xml::sax::XFastContextHandler > xResult;
2133 
2134     Id nNameSpace = Element & 0xffff0000;
2135 
2136 #ifdef DEBUG_CONTEXT_HANDLER
2137     debug_logger->startElement("Wrapper-createChildContext");
2138     debug_logger->attribute("token", fastTokenToId(Element));
2139 
2140     set<Id>::const_iterator aIt(mMyNamespaces.begin());
2141     while (aIt != mMyNamespaces.end())
2142     {
2143         debug_logger->startElement("namespace");
2144         debug_logger->attribute("id", fastTokenToId(*aIt));
2145         debug_logger->endElement("namespace");
2146 
2147         aIt++;
2148     }
2149 
2150     debug_logger->endElement("Wrapper-createChildContext");
2151 #endif
2152 
2153     bool bInNamespaces = mMyNamespaces.find(nNameSpace) != mMyNamespaces.end();
2154     bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( );
2155     if ( bInNamespaces )
2156         xResult.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
2157     else if (mxContext.is())
2158     {
2159         OOXMLFastContextHandlerWrapper * pWrapper =
2160             new OOXMLFastContextHandlerWrapper
2161             (this, mxContext->createFastChildContext(Element, Attribs));
2162         pWrapper->mMyNamespaces = mMyNamespaces;
2163         pWrapper->setPropertySet(getPropertySet());
2164         xResult.set(pWrapper);
2165     }
2166     else
2167         xResult.set(this);
2168 
2169     if ( bInTokens )
2170     {
2171         OOXMLFastContextHandlerShape* pShapeCtx = (OOXMLFastContextHandlerShape*)mpParent;
2172         pShapeCtx->sendShape( Element );
2173     }
2174 
2175     return xResult;
2176 }
2177 
lcl_characters(const::rtl::OUString & aChars)2178 void OOXMLFastContextHandlerWrapper::lcl_characters
2179 (const ::rtl::OUString & aChars)
2180     throw (uno::RuntimeException, xml::sax::SAXException)
2181 {
2182     if (mxContext.is())
2183         mxContext->characters(aChars);
2184 }
2185 
2186 OOXMLFastContextHandler *
getFastContextHandler() const2187 OOXMLFastContextHandlerWrapper::getFastContextHandler() const
2188 {
2189     if (mxContext.is())
2190         return dynamic_cast<OOXMLFastContextHandler *>(mxContext.get());
2191 
2192     return NULL;
2193 }
2194 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)2195 void OOXMLFastContextHandlerWrapper::newProperty
2196 (const Id & rId, OOXMLValue::Pointer_t pVal)
2197 {
2198     if (mxContext.is())
2199     {
2200         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2201         if (pHandler != NULL)
2202             pHandler->newProperty(rId, pVal);
2203     }
2204 }
2205 
setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet)2206 void OOXMLFastContextHandlerWrapper::setPropertySet
2207 (OOXMLPropertySet::Pointer_t pPropertySet)
2208 {
2209     if (mxContext.is())
2210     {
2211         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2212         if (pHandler != NULL)
2213             pHandler->setPropertySet(pPropertySet);
2214     }
2215 
2216     mpPropertySet = pPropertySet;
2217 }
2218 
getPropertySet() const2219 OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerWrapper::getPropertySet()
2220     const
2221 {
2222     OOXMLPropertySet::Pointer_t pResult(mpPropertySet);
2223 
2224     if (mxContext.is())
2225     {
2226         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2227         if (pHandler != NULL)
2228             pResult = pHandler->getPropertySet();
2229     }
2230 
2231     return pResult;
2232 }
2233 
getType() const2234 string OOXMLFastContextHandlerWrapper::getType() const
2235 {
2236     string sResult = "Wrapper(";
2237 
2238     if (mxContext.is())
2239     {
2240         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2241         if (pHandler != NULL)
2242             sResult += pHandler->getType();
2243     }
2244 
2245     sResult += ")";
2246 
2247     return sResult;
2248 }
2249 
setId(Id rId)2250 void OOXMLFastContextHandlerWrapper::setId(Id rId)
2251 {
2252     OOXMLFastContextHandler::setId(rId);
2253 
2254     if (mxContext.is())
2255     {
2256         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2257         if (pHandler != NULL)
2258             pHandler->setId(rId);
2259     }
2260 }
2261 
getId() const2262 Id OOXMLFastContextHandlerWrapper::getId() const
2263 {
2264     Id nResult = OOXMLFastContextHandler::getId();
2265 
2266     if (mxContext.is())
2267     {
2268         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2269         if (pHandler != NULL && pHandler->getId() != 0)
2270             nResult = pHandler->getId();
2271     }
2272 
2273     return nResult;
2274 }
2275 
setToken(Token_t nToken)2276 void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken)
2277 {
2278     OOXMLFastContextHandler::setToken(nToken);
2279 
2280     if (mxContext.is())
2281     {
2282         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2283         if (pHandler != NULL)
2284             pHandler->setToken(nToken);
2285     }
2286 }
2287 
getToken() const2288 Token_t OOXMLFastContextHandlerWrapper::getToken() const
2289 {
2290     Token_t nResult = OOXMLFastContextHandler::getToken();
2291 
2292     if (mxContext.is())
2293     {
2294         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2295         if (pHandler != NULL)
2296             nResult = pHandler->getToken();
2297     }
2298 
2299     return nResult;
2300 }
2301 
2302 }}
2303