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(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)183 void SAL_CALL OOXMLFastContextHandler::startFastElement
184 (Token_t 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(Token_t Element)219 void SAL_CALL OOXMLFastContextHandler::endFastElement(Token_t 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(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> &)238 void OOXMLFastContextHandler::lcl_startFastElement
239 (Token_t 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(Token_t Element)246 void OOXMLFastContextHandler::lcl_endFastElement
247 (Token_t 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(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)264  OOXMLFastContextHandler::createFastChildContext
265 (Token_t 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(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> &)286  OOXMLFastContextHandler::lcl_createFastChildContext
287 (Token_t 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(Token_t Element)366 void OOXMLFastContextHandler::startAction(Token_t 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(Token_t Element)377 void OOXMLFastContextHandler::lcl_startAction(Token_t Element)
378 {
379     OOXMLFactory::getInstance()->startAction(this, Element);
380 }
381 
endAction(Token_t Element)382 void OOXMLFastContextHandler::endAction(Token_t 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(Token_t Element)393 void OOXMLFastContextHandler::lcl_endAction(Token_t 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 #ifdef DEBUG_CONTEXT_HANDLER
496     msTokenString = fastTokenToId(mnToken);
497 #endif
498 }
499 
getToken() const500 Token_t OOXMLFastContextHandler::getToken() const
501 {
502     return mnToken;
503 }
504 
mark(const Id & rId,OOXMLValue::Pointer_t pVal)505 void OOXMLFastContextHandler::mark(const Id & rId, OOXMLValue::Pointer_t pVal)
506 {
507     OOXMLPropertySetImpl::Pointer_t pPropSet(new OOXMLPropertySetImpl());
508     OOXMLPropertyImpl::Pointer_t pProperty
509         (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
510 
511     pPropSet->add(pProperty);
512     mpStream->props(pPropSet);
513 }
514 
setParent(OOXMLFastContextHandler * pParent)515 void OOXMLFastContextHandler::setParent
516 (OOXMLFastContextHandler * pParent)
517 {
518     mpParent = pParent;
519 }
520 
getPicturePropSet(const::rtl::OUString & rId)521 OOXMLPropertySet * OOXMLFastContextHandler::getPicturePropSet
522 (const ::rtl::OUString & rId)
523 {
524     return dynamic_cast<OOXMLDocumentImpl *>(mpParserState->getDocument())->
525         getPicturePropSet(rId);
526 }
527 
sendTableDepth() const528 void OOXMLFastContextHandler::sendTableDepth() const
529 {
530 #ifdef DEBUG_CONTEXT_HANDLER
531     debug_logger->startElement("contexthandler.sendTableDepth");
532 #endif
533 
534     if (mnTableDepth > 0)
535     {
536         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
537         {
538             OOXMLValue::Pointer_t pVal
539                 (new OOXMLIntegerValue(mnTableDepth));
540             OOXMLProperty::Pointer_t pProp
541                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
542             pProps->add(pProp);
543         }
544         {
545             OOXMLValue::Pointer_t pVal
546                 (new OOXMLIntegerValue(1));
547             OOXMLProperty::Pointer_t pProp
548                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
549             pProps->add(pProp);
550         }
551 
552         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
553     }
554 #ifdef DEBUG_CONTEXT_HANDLER
555     debug_logger->endElement("contexthandler.sendTableDepth");
556 #endif
557 }
558 
setHandle()559 void OOXMLFastContextHandler::setHandle()
560 {
561     mpParserState->setHandle();
562     mpStream->info(mpParserState->getHandle());
563 }
564 
startCharacterGroup()565 void OOXMLFastContextHandler::startCharacterGroup()
566 {
567 #ifdef DEBUG_CONTEXT_HANDLER
568     debug_logger->element("contexthandler.startCharacterGroup");
569 #endif
570 
571     if (isForwardEvents())
572     {
573         if (mpParserState->isInCharacterGroup())
574             endCharacterGroup();
575 
576         if (! mpParserState->isInParagraphGroup())
577             startParagraphGroup();
578 
579         if (! mpParserState->isInCharacterGroup())
580         {
581             mpStream->startCharacterGroup();
582             mpParserState->setInCharacterGroup(true);
583             mpParserState->resolveCharacterProperties(*mpStream);
584         }
585     }
586 }
587 
endCharacterGroup()588 void OOXMLFastContextHandler::endCharacterGroup()
589 {
590 #ifdef DEBUG_CONTEXT_HANDLER
591     debug_logger->element("contexthandler.endCharacterGroup");
592 #endif
593 
594     if (isForwardEvents() && mpParserState->isInCharacterGroup())
595     {
596         mpStream->endCharacterGroup();
597         mpParserState->setInCharacterGroup(false);
598     }
599 }
600 
startParagraphGroup()601 void OOXMLFastContextHandler::startParagraphGroup()
602 {
603 #ifdef DEBUG_CONTEXT_HANDLER
604     debug_logger->element("contexthandler.startParagraphGroup");
605 #endif
606 
607     if (isForwardEvents())
608     {
609         if (mpParserState->isInParagraphGroup())
610             endParagraphGroup();
611 
612         if (! mpParserState->isInSectionGroup())
613             startSectionGroup();
614 
615         if (! mpParserState->isInParagraphGroup())
616         {
617             mpStream->startParagraphGroup();
618             mpParserState->setInParagraphGroup(true);
619         }
620     }
621 }
622 
endParagraphGroup()623 void OOXMLFastContextHandler::endParagraphGroup()
624 {
625 #ifdef DEBUG_CONTEXT_HANDLER
626     debug_logger->element("contexthandler.endParagraphGroup");
627 #endif
628 
629     if (isForwardEvents())
630     {
631         if (mpParserState->isInCharacterGroup())
632             endCharacterGroup();
633 
634         if (mpParserState->isInParagraphGroup())
635         {
636             mpStream->endParagraphGroup();
637             mpParserState->setInParagraphGroup(false);
638         }
639     }
640 }
641 
startSectionGroup()642 void OOXMLFastContextHandler::startSectionGroup()
643 {
644 #ifdef DEBUG_CONTEXT_HANDLER
645     debug_logger->element("contexthandler.startSectionGroup");
646 #endif
647 
648     if (isForwardEvents())
649     {
650         if (mpParserState->isInSectionGroup())
651             endSectionGroup();
652 
653         if (! mpParserState->isInSectionGroup())
654         {
655             mpStream->info(mpParserState->getHandle());
656             mpStream->startSectionGroup();
657             mpParserState->setInSectionGroup(true);
658         }
659     }
660 }
661 
endSectionGroup()662 void OOXMLFastContextHandler::endSectionGroup()
663 {
664 #ifdef DEBUG_CONTEXT_HANDLER
665     debug_logger->element("contexthandler.endSectionGroup");
666 #endif
667 
668     if (isForwardEvents())
669     {
670         if (mpParserState->isInParagraphGroup())
671             endParagraphGroup();
672 
673         if (mpParserState->isInSectionGroup())
674         {
675             mpStream->endSectionGroup();
676             mpParserState->setInSectionGroup(false);
677         }
678     }
679 }
680 
setLastParagraphInSection()681 void OOXMLFastContextHandler::setLastParagraphInSection()
682 {
683     mpParserState->setLastParagraphInSection(true);
684     mpStream->markLastParagraphInSection( );
685 }
686 
newProperty(const Id &,OOXMLValue::Pointer_t)687 void OOXMLFastContextHandler::newProperty
688 (const Id & /*nId*/, OOXMLValue::Pointer_t /*pVal*/)
689 {
690 }
691 
setPropertySet(OOXMLPropertySet::Pointer_t)692 void OOXMLFastContextHandler::setPropertySet
693 (OOXMLPropertySet::Pointer_t /* pPropertySet */)
694 {
695 }
696 
getPropertySet() const697 OOXMLPropertySet::Pointer_t OOXMLFastContextHandler::getPropertySet() const
698 {
699     return OOXMLPropertySet::Pointer_t();
700 }
701 
startField()702 void OOXMLFastContextHandler::startField()
703 {
704 #ifdef DEBUG_CONTEXT_HANDLER
705     debug_logger->element("contexthandler.startField");
706 #endif
707     startCharacterGroup();
708     if (isForwardEvents())
709         mpStream->text(sFieldStart, 1);
710     endCharacterGroup();
711 }
712 
fieldSeparator()713 void OOXMLFastContextHandler::fieldSeparator()
714 {
715 #ifdef DEBUG_CONTEXT_HANDLER
716     debug_logger->element("contexthandler.fieldSeparator");
717 #endif
718     startCharacterGroup();
719     if (isForwardEvents())
720         mpStream->text(sFieldSep, 1);
721     endCharacterGroup();
722 }
723 
endField()724 void OOXMLFastContextHandler::endField()
725 {
726 #ifdef DEBUG_CONTEXT_HANDLER
727     debug_logger->element("contexthandler.endField");
728 #endif
729     startCharacterGroup();
730     if (isForwardEvents())
731         mpStream->text(sFieldEnd, 1);
732     endCharacterGroup();
733 }
734 
ftnednref()735 void OOXMLFastContextHandler::ftnednref()
736 {
737 #ifdef DEBUG_CONTEXT_HANDLER
738     debug_logger->element("contexthandler.ftnednref");
739 #endif
740     if (isForwardEvents())
741         mpStream->utext(sFtnEdnRef, 1);
742 }
743 
ftnednsep()744 void OOXMLFastContextHandler::ftnednsep()
745 {
746 #ifdef DEBUG_CONTEXT_HANDLER
747     debug_logger->element("contexthandler.ftnednsep");
748 #endif
749     if (isForwardEvents())
750         mpStream->utext(sFtnEdnSep, 1);
751 }
752 
ftnedncont()753 void OOXMLFastContextHandler::ftnedncont()
754 {
755 #ifdef DEBUG_CONTEXT_HANDLER
756     debug_logger->element("contexthandler.ftnedncont");
757 #endif
758     if (isForwardEvents())
759         mpStream->text(sFtnEdnCont, 1);
760 }
761 
pgNum()762 void OOXMLFastContextHandler::pgNum()
763 {
764 #ifdef DEBUG_CONTEXT_HANDLER
765     debug_logger->element("contexthandler.pgNum");
766 #endif
767     if (isForwardEvents())
768         mpStream->utext((const sal_uInt8*)sPgNum, 1);
769 }
770 
tab()771 void OOXMLFastContextHandler::tab()
772 {
773 #ifdef DEBUG_CONTEXT_HANDLER
774     debug_logger->element("contexthandler.tab");
775 #endif
776     if (isForwardEvents())
777         mpStream->utext((const sal_uInt8*)sTab, 1);
778 }
779 
cr()780 void OOXMLFastContextHandler::cr()
781 {
782 #ifdef DEBUG_CONTEXT_HANDLER
783     debug_logger->element("contexthandler.cr");
784 #endif
785     if (isForwardEvents())
786         mpStream->utext((const sal_uInt8*)sCR, 1);
787 }
788 
noBreakHyphen()789 void OOXMLFastContextHandler::noBreakHyphen()
790 {
791 #ifdef DEBUG_CONTEXT_HANDLER
792     debug_logger->element("contexthandler.noBreakHyphen");
793 #endif
794     if (isForwardEvents())
795         mpStream->utext((const sal_uInt8*)sNoBreakHyphen, 1);
796 }
797 
softHyphen()798 void OOXMLFastContextHandler::softHyphen()
799 {
800 #ifdef DEBUG_CONTEXT_HANDLER
801     debug_logger->element("contexthandler.softHyphen");
802 #endif
803     if (isForwardEvents())
804         mpStream->utext((const sal_uInt8*)sSoftHyphen, 1);
805 }
806 
handleLastParagraphInSection()807 void OOXMLFastContextHandler::handleLastParagraphInSection()
808 {
809 #ifdef DEBUG_CONTEXT_HANDLER
810     debug_logger->element("contexthandler.handleLastParagraphInSection");
811 #endif
812 
813     if (mpParserState->isLastParagraphInSection())
814     {
815         mpParserState->setLastParagraphInSection(false);
816         startSectionGroup();
817     }
818 }
819 
endOfParagraph()820 void OOXMLFastContextHandler::endOfParagraph()
821 {
822 #ifdef DEBUG_CONTEXT_HANDLER
823     debug_logger->element("contexthandler.endOfParagraph");
824 #endif
825     if (! mpParserState->isInCharacterGroup())
826         startCharacterGroup();
827     if (isForwardEvents())
828         mpStream->utext((const sal_uInt8*)sCR, 1);
829 }
830 
text(const::rtl::OUString & sText)831 void OOXMLFastContextHandler::text(const ::rtl::OUString & sText)
832 {
833 #ifdef DEBUG_CONTEXT_HANDLER
834     debug_logger->startElement("contexthandler.text");
835     debug_logger->chars(sText);
836     debug_logger->endElement("contexthandler.text");
837 #endif
838     if (isForwardEvents())
839         mpStream->utext(reinterpret_cast < const sal_uInt8 * >
840                         (sText.getStr()),
841                         sText.getLength());
842 }
843 
propagateCharacterProperties()844 void OOXMLFastContextHandler::propagateCharacterProperties()
845 {
846 #ifdef DEBUG_CONTEXT_HANDLER
847     debug_logger->startElement("contexthandler.propagateCharacterProperties");
848     debug_logger->addTag(toPropertiesTag(getPropertySet()));
849     debug_logger->endElement("contexthandler.propagateCharacterProperties");
850 #endif
851 
852     mpParserState->setCharacterProperties(getPropertySet());
853 }
854 
propagateCharacterPropertiesAsSet(const Id & rId)855 void OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const Id & rId)
856 {
857 #ifdef DEBUG_CONTEXT_HANDLER
858     debug_logger->startElement("contexthandler.propagateCharacterPropertiesAsSet");
859     debug_logger->addTag(toPropertiesTag(getPropertySet()));
860     debug_logger->endElement("contexthandler.propagateCharacterPropertiesAsSet");
861 #endif
862 
863     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
864     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
865 
866     OOXMLProperty::Pointer_t pProp
867         (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
868 
869     pPropertySet->add(pProp);
870     mpParserState->setCharacterProperties(pPropertySet);
871 }
872 
propagatesProperties() const873 bool OOXMLFastContextHandler::propagatesProperties() const
874 {
875     return false;
876 }
877 
propagateCellProperties()878 void OOXMLFastContextHandler::propagateCellProperties()
879 {
880 #ifdef DEBUG_CONTEXT_HANDLER
881     debug_logger->element("contexthandler.propagateCellProperties");
882 #endif
883 
884     mpParserState->setCellProperties(getPropertySet());
885 }
886 
propagateRowProperties()887 void OOXMLFastContextHandler::propagateRowProperties()
888 {
889 #ifdef DEBUG_CONTEXT_HANDLER
890     debug_logger->element("contexthandler.propagateRowProperties");
891 #endif
892 
893     mpParserState->setRowProperties(getPropertySet());
894 }
895 
propagateTableProperties()896 void OOXMLFastContextHandler::propagateTableProperties()
897 {
898     OOXMLPropertySet::Pointer_t pProps = getPropertySet();
899 #ifdef DEBUG_CONTEXT_HANDLER
900     debug_logger->startElement("contexthandler.propagateTableProperties");
901     debug_logger->addTag(toPropertiesTag(pProps));
902     debug_logger->endElement("contexthandler.propagateTableProperties");
903 #endif
904 
905     mpParserState->setTableProperties(pProps);
906 }
907 
sendCellProperties()908 void OOXMLFastContextHandler::sendCellProperties()
909 {
910 #ifdef DEBUG_CONTEXT_HANDLER
911     debug_logger->startElement("contexthandler.sendCellProperties");
912 #endif
913 
914     mpParserState->resolveCellProperties(*mpStream);
915 
916 #ifdef DEBUG_CONTEXT_HANDLER
917     debug_logger->endElement("contexthandler.sendCellProperties");
918 #endif
919 }
920 
sendRowProperties()921 void OOXMLFastContextHandler::sendRowProperties()
922 {
923 #ifdef DEBUG_CONTEXT_HANDLER
924     debug_logger->startElement("contexthandler.sendRowProperties");
925 #endif
926 
927     mpParserState->resolveRowProperties(*mpStream);
928 
929 #ifdef DEBUG_CONTEXT_HANDLER
930     debug_logger->endElement("contexthandler.sendRowProperties");
931 #endif
932 }
933 
sendTableProperties()934 void OOXMLFastContextHandler::sendTableProperties()
935 {
936 #ifdef DEBUG_CONTEXT_HANDLER
937     debug_logger->startElement("contexthandler.sendTableProperties");
938 #endif
939 
940     mpParserState->resolveTableProperties(*mpStream);
941 
942 #ifdef DEBUG_CONTEXT_HANDLER
943     debug_logger->endElement("contexthandler.sendTableProperties");
944 #endif
945 }
946 
clearTableProps()947 void OOXMLFastContextHandler::clearTableProps()
948 {
949 #ifdef DEBUG_CONTEXT_HANDLER
950     debug_logger->element("contexthandler.clearTableProps");
951 #endif
952 
953     mpParserState->setTableProperties(OOXMLPropertySet::Pointer_t
954                                      (new OOXMLPropertySetImpl()));
955 }
956 
sendPropertiesWithId(const Id & rId)957 void OOXMLFastContextHandler::sendPropertiesWithId(const Id & rId)
958 {
959 #ifdef DEBUG_CONTEXT_HANDLER
960     debug_logger->startElement("contexthandler.sendPropertiesWithId");
961     debug_logger->attribute("id", fastTokenToId(rId));
962 #endif
963 
964     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
965     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
966 
967     OOXMLProperty::Pointer_t pProp
968     (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
969 
970     pPropertySet->add(pProp);
971     mpStream->props(pPropertySet);
972 
973 #ifdef DEBUG_CONTEXT_HANDLER
974     debug_logger->addTag(toPropertiesTag(pPropertySet));
975     debug_logger->endElement("contexthandler.sendPropertiesWithId");
976 #endif
977 }
978 
clearProps()979 void OOXMLFastContextHandler::clearProps()
980 {
981 #ifdef DEBUG_CONTEXT_HANDLER
982     debug_logger->element("contexthandler.clearProps");
983 #endif
984 
985     setPropertySet(OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl()));
986 }
987 
setDefaultBooleanValue()988 void OOXMLFastContextHandler::setDefaultBooleanValue()
989 {
990 }
991 
setDefaultIntegerValue()992 void OOXMLFastContextHandler::setDefaultIntegerValue()
993 {
994 }
995 
setDefaultHexValue()996 void OOXMLFastContextHandler::setDefaultHexValue()
997 {
998 }
999 
setDefaultStringValue()1000 void OOXMLFastContextHandler::setDefaultStringValue()
1001 {
1002 }
1003 
setDocument(OOXMLDocument * pDocument)1004 void OOXMLFastContextHandler::setDocument(OOXMLDocument * pDocument)
1005 {
1006     mpParserState->setDocument(pDocument);
1007 }
1008 
getDocument()1009 OOXMLDocument * OOXMLFastContextHandler::getDocument()
1010 {
1011     return mpParserState->getDocument();
1012 }
1013 
setForwardEvents(bool bForwardEvents)1014 void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents)
1015 {
1016 #ifdef DEBUG_CONTEXT_HANDLER
1017     debug_logger->startElement("contexthandler.setForwardEvents");
1018 
1019     if (bForwardEvents)
1020         debug_logger->chars("true");
1021     else
1022         debug_logger->chars("false");
1023 
1024     debug_logger->endElement("contexthandler.setForwardEvents");
1025 #endif
1026 
1027     mpParserState->setForwardEvents(bForwardEvents);
1028 }
1029 
isForwardEvents() const1030 bool OOXMLFastContextHandler::isForwardEvents() const
1031 {
1032     return mpParserState->isForwardEvents();
1033 }
1034 
1035 
setIDForXNoteStream(OOXMLValue::Pointer_t pValue)1036 void OOXMLFastContextHandler::setIDForXNoteStream(OOXMLValue::Pointer_t pValue)
1037 {
1038     mpParserState->getDocument()->setIDForXNoteStream(pValue->getInt());
1039 }
1040 
1041 
resolveFootnote(const sal_Int32 nIDForXNoteStream)1042 void OOXMLFastContextHandler::resolveFootnote(
1043     const sal_Int32 nIDForXNoteStream )
1044 {
1045     mpParserState->getDocument()->resolveFootnote
1046         (*mpStream, 0, nIDForXNoteStream);
1047 }
1048 
resolveEndnote(const sal_Int32 nIDForXNoteStream)1049 void OOXMLFastContextHandler::resolveEndnote(
1050     const sal_Int32 nIDForXNoteStream )
1051 {
1052     mpParserState->getDocument()->resolveEndnote
1053         (*mpStream, 0, nIDForXNoteStream);
1054 }
1055 
resolveComment(const sal_Int32 nIDForXNoteStream)1056 void OOXMLFastContextHandler::resolveComment(
1057     const sal_Int32 nIDForXNoteStream )
1058 {
1059     mpParserState->getDocument()->resolveComment(*mpStream, nIDForXNoteStream);
1060 }
1061 
resolvePicture(const rtl::OUString & rId)1062 void OOXMLFastContextHandler::resolvePicture(const rtl::OUString & rId)
1063 {
1064     mpParserState->getDocument()->resolvePicture(*mpStream, rId);
1065 }
1066 
resolveHeader(const sal_Int32 type,const rtl::OUString & rId)1067 void OOXMLFastContextHandler::resolveHeader
1068 (const sal_Int32 type, const rtl::OUString & rId)
1069 {
1070     mpParserState->getDocument()->resolveHeader(*mpStream, type, rId);
1071 }
1072 
resolveFooter(const sal_Int32 type,const rtl::OUString & rId)1073 void OOXMLFastContextHandler::resolveFooter
1074 (const sal_Int32 type, const rtl::OUString & rId)
1075 {
1076     mpParserState->getDocument()->resolveFooter(*mpStream, type, rId);
1077 }
1078 
resolveOLE(const rtl::OUString & rId)1079 void OOXMLFastContextHandler::resolveOLE(const rtl::OUString & rId)
1080 {
1081     uno::Reference<io::XInputStream> xInputStream
1082         (mpParserState->getDocument()->getInputStreamForId(rId));
1083 
1084     OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream));
1085 
1086     newProperty(NS_ooxml::LN_inputstream, aValue);
1087 }
1088 
getTargetForId(const::rtl::OUString & rId)1089 ::rtl::OUString OOXMLFastContextHandler::getTargetForId
1090 (const ::rtl::OUString & rId)
1091 {
1092     return mpParserState->getDocument()->getTargetForId(rId);
1093 }
1094 
resolvePropertySetAttrs()1095 void OOXMLFastContextHandler::resolvePropertySetAttrs()
1096 {
1097 }
1098 
sendPropertyToParent()1099 void OOXMLFastContextHandler::sendPropertyToParent()
1100 {
1101 #ifdef DEBUG_CONTEXT_HANDLER
1102     debug_logger->startElement("contexthandler.sendPropertyToParent");
1103 #endif
1104 
1105     if (mpParent != NULL)
1106     {
1107         OOXMLPropertySet::Pointer_t pProps(mpParent->getPropertySet());
1108 
1109         if (pProps.get() != NULL)
1110         {
1111             OOXMLProperty::Pointer_t
1112                 pProp(new OOXMLPropertyImpl(mId, getValue(),
1113                                             OOXMLPropertyImpl::SPRM));
1114             pProps->add(pProp);
1115 
1116 #ifdef DEBUG_CONTEXT_HANDLER
1117             debug_logger->addTag(toPropertiesTag(pProps));
1118 #endif
1119         }
1120     }
1121 
1122 #ifdef DEBUG_CONTEXT_HANDLER
1123     debug_logger->endElement("contexthandler.sendPropertyToParent");
1124 #endif
1125 }
1126 
sendPropertiesToParent()1127 void OOXMLFastContextHandler::sendPropertiesToParent()
1128 {
1129 #ifdef DEBUG_CONTEXT_HANDLER
1130     debug_logger->startElement("contexthandler.sendPropertiesToParent");
1131 #endif
1132     if (mpParent != NULL)
1133     {
1134         OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet());
1135 
1136         if (pParentProps.get() != NULL)
1137         {
1138             OOXMLPropertySet::Pointer_t pProps(getPropertySet());
1139 
1140             if (pProps.get() != NULL)
1141             {
1142                 OOXMLValue::Pointer_t pValue
1143                 (new OOXMLPropertySetValue(getPropertySet()));
1144 
1145                 OOXMLProperty::Pointer_t pProp
1146                 (new OOXMLPropertyImpl(getId(), pValue, OOXMLPropertyImpl::SPRM));
1147 
1148                 pParentProps->add(pProp);
1149             }
1150         }
1151     }
1152 #ifdef DEBUG_CONTEXT_HANDLER
1153     debug_logger->endElement("contexthandler.sendPropertiesToParent");
1154 #endif
1155 }
1156 
1157 uno::Reference< uno::XComponentContext >
getComponentContext()1158 OOXMLFastContextHandler::getComponentContext()
1159 {
1160     return m_xContext;
1161 }
1162 
1163 /*
1164   class OOXMLFastContextHandlerStream
1165  */
1166 
OOXMLFastContextHandlerStream(OOXMLFastContextHandler * pContext)1167 OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
1168 (OOXMLFastContextHandler * pContext)
1169 : OOXMLFastContextHandler(pContext),
1170   mpPropertySetAttrs(new OOXMLPropertySetImpl())
1171 {
1172 }
1173 
~OOXMLFastContextHandlerStream()1174 OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
1175 {
1176 }
1177 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)1178 void OOXMLFastContextHandlerStream::newProperty(const Id & rId,
1179                                                 OOXMLValue::Pointer_t pVal)
1180 {
1181     if (rId != 0x0)
1182     {
1183         OOXMLPropertyImpl::Pointer_t pProperty
1184             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
1185 
1186         mpPropertySetAttrs->add(pProperty);
1187     }
1188 }
1189 
sendProperty(Id nId)1190 void OOXMLFastContextHandlerStream::sendProperty(Id nId)
1191 {
1192 #ifdef DEBUG_CONTEXT_HANDLER
1193     debug_logger->startElement("contexthandler.sendProperty");
1194     debug_logger->attribute("id", (*QNameToString::Instance())(nId));
1195     debug_logger->chars(xmlify(getPropertySetAttrs()->toString()));
1196     debug_logger->endElement("contexthandler.sendProperty");
1197 #endif
1198 
1199     OOXMLPropertySetEntryToString aHandler(nId);
1200     getPropertySetAttrs()->resolve(aHandler);
1201     const ::rtl::OUString & sText = aHandler.getString();
1202     mpStream->utext(reinterpret_cast < const sal_uInt8 * >
1203                     (sText.getStr()),
1204                     sText.getLength());
1205 }
1206 
1207 OOXMLPropertySet::Pointer_t
getPropertySetAttrs() const1208 OOXMLFastContextHandlerStream::getPropertySetAttrs() const
1209 {
1210     return mpPropertySetAttrs;
1211 }
1212 
resolvePropertySetAttrs()1213 void OOXMLFastContextHandlerStream::resolvePropertySetAttrs()
1214 {
1215 #ifdef DEBUG_CONTEXT_HANDLER
1216         debug_logger->startElement("contexthandler.resolvePropertySetAttrs");
1217         debug_logger->chars(mpPropertySetAttrs->toString());
1218         debug_logger->endElement("contexthandler.resolvePropertySetAttrs");
1219 #endif
1220     mpStream->props(mpPropertySetAttrs);
1221 }
1222 
getPropertySet() const1223 OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerStream::getPropertySet()
1224     const
1225 {
1226     return getPropertySetAttrs();
1227 }
1228 
handleHyperlink()1229 void OOXMLFastContextHandlerStream::handleHyperlink()
1230 {
1231     OOXMLHyperlinkHandler aHyperlinkHandler(this);
1232     getPropertySetAttrs()->resolve(aHyperlinkHandler);
1233 }
1234 
lcl_characters(const::rtl::OUString & rChars)1235 void OOXMLFastContextHandlerStream::lcl_characters
1236 (const ::rtl::OUString & rChars)
1237 throw (uno::RuntimeException, xml::sax::SAXException)
1238 {
1239     text(rChars);
1240 }
1241 
1242 /*
1243   class OOXMLFastContextHandlerProperties
1244  */
OOXMLFastContextHandlerProperties(OOXMLFastContextHandler * pContext)1245 OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties
1246 (OOXMLFastContextHandler * pContext)
1247 : OOXMLFastContextHandler(pContext), mpPropertySet(new OOXMLPropertySetImpl()),
1248   mbResolve(false)
1249 {
1250     if (pContext->getResource() == STREAM)
1251         mbResolve = true;
1252 }
1253 
~OOXMLFastContextHandlerProperties()1254 OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties()
1255 {
1256 }
1257 
lcl_endFastElement(Token_t Element)1258 void OOXMLFastContextHandlerProperties::lcl_endFastElement
1259 (Token_t Element)
1260     throw (uno::RuntimeException, xml::sax::SAXException)
1261 {
1262     endAction(Element);
1263 
1264     if (mbResolve)
1265     {
1266         if (isForwardEvents())
1267         {
1268             mpStream->props(mpPropertySet);
1269         }
1270     }
1271     else
1272     {
1273         sendPropertiesToParent();
1274     }
1275 }
1276 
getValue() const1277 OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const
1278 {
1279     return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet));
1280 }
1281 
1282 #ifdef DEBUG
toTag() const1283 XMLTag::Pointer_t OOXMLFastContextHandlerProperties::toTag() const
1284 {
1285     XMLTag::Pointer_t pTag(OOXMLFastContextHandler::toTag());
1286     pTag->addAttr("resolve", mbResolve ? "resolve" : "noResolve");
1287 
1288     return pTag;
1289 }
1290 #endif
1291 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)1292 void OOXMLFastContextHandlerProperties::newProperty
1293 (const Id & rId, OOXMLValue::Pointer_t pVal)
1294 {
1295     if (rId != 0x0)
1296     {
1297         OOXMLPropertyImpl::Pointer_t pProperty
1298             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
1299 
1300         mpPropertySet->add(pProperty);
1301     }
1302 }
1303 
handleXNotes()1304 void OOXMLFastContextHandlerProperties::handleXNotes()
1305 {
1306     switch (mnToken)
1307     {
1308     case NS_wordprocessingml|OOXML_footnoteReference:
1309         {
1310             OOXMLFootnoteHandler aFootnoteHandler(this);
1311             mpPropertySet->resolve(aFootnoteHandler);
1312         }
1313         break;
1314     case NS_wordprocessingml|OOXML_endnoteReference:
1315         {
1316             OOXMLEndnoteHandler aEndnoteHandler(this);
1317             mpPropertySet->resolve(aEndnoteHandler);
1318         }
1319         break;
1320     default:
1321         break;
1322     }
1323 }
1324 
handleHdrFtr()1325 void OOXMLFastContextHandlerProperties::handleHdrFtr()
1326 {
1327     switch (mnToken)
1328     {
1329     case NS_wordprocessingml|OOXML_footerReference:
1330         {
1331             OOXMLFooterHandler aFooterHandler(this);
1332             mpPropertySet->resolve(aFooterHandler);
1333         }
1334         break;
1335     case NS_wordprocessingml|OOXML_headerReference:
1336         {
1337             OOXMLHeaderHandler aHeaderHandler(this);
1338             mpPropertySet->resolve(aHeaderHandler);
1339         }
1340         break;
1341     default:
1342         break;
1343     }
1344 }
1345 
handleComment()1346 void OOXMLFastContextHandlerProperties::handleComment()
1347 {
1348 #ifdef DEBUG_ELEMENT
1349     debug_logger->element("handleComment");
1350 #endif
1351 
1352     OOXMLCommentHandler aCommentHandler(this);
1353     getPropertySet()->resolve(aCommentHandler);
1354 }
1355 
handlePicture()1356 void OOXMLFastContextHandlerProperties::handlePicture()
1357 {
1358 #ifdef DEBUG_ELEMENT
1359     debug_logger->element("handlePicture");
1360 #endif
1361 
1362     OOXMLPictureHandler aPictureHandler(this);
1363     getPropertySet()->resolve(aPictureHandler);
1364 }
1365 
handleBreak()1366 void OOXMLFastContextHandlerProperties::handleBreak()
1367 {
1368 #ifdef DEBUG_ELEMENT
1369     debug_logger->element("handleBreak");
1370 #endif
1371 
1372     OOXMLBreakHandler aBreakHandler(*mpStream, this);
1373     getPropertySet()->resolve(aBreakHandler);
1374 }
1375 
handleOLE()1376 void OOXMLFastContextHandlerProperties::handleOLE()
1377 {
1378 #ifdef DEBUG_ELEMENT
1379     debug_logger->element("handleOLE");
1380 #endif
1381 
1382     OOXMLOLEHandler aOLEHandler(this);
1383     getPropertySet()->resolve(aOLEHandler);
1384 }
1385 
setParent(OOXMLFastContextHandler * pParent)1386 void OOXMLFastContextHandlerProperties::setParent
1387 (OOXMLFastContextHandler * pParent)
1388 {
1389 #ifdef DEBUG_ELEMENT
1390     debug_logger->startElement("setParent");
1391     debug_logger->chars("OOXMLFastContextHandlerProperties");
1392     debug_logger->endElement("setParent");
1393 #endif
1394 
1395     OOXMLFastContextHandler::setParent(pParent);
1396 
1397     if (mpParent->getResource() == STREAM)
1398         mbResolve = true;
1399 }
1400 
setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet)1401 void OOXMLFastContextHandlerProperties::setPropertySet
1402 (OOXMLPropertySet::Pointer_t pPropertySet)
1403 {
1404     if (pPropertySet.get() != NULL)
1405         mpPropertySet = pPropertySet;
1406 }
1407 
1408 OOXMLPropertySet::Pointer_t
getPropertySet() const1409 OOXMLFastContextHandlerProperties::getPropertySet() const
1410 {
1411     return mpPropertySet;
1412 }
1413 
1414 /*
1415  * class OOXMLFasContextHandlerPropertyTable
1416  */
1417 
OOXMLFastContextHandlerPropertyTable(OOXMLFastContextHandler * pContext)1418 OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable
1419 (OOXMLFastContextHandler * pContext)
1420 : OOXMLFastContextHandlerProperties(pContext)
1421 {
1422 }
1423 
~OOXMLFastContextHandlerPropertyTable()1424 OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable()
1425 {
1426 }
1427 
lcl_endFastElement(Token_t Element)1428 void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement
1429 (Token_t Element)
1430     throw (uno::RuntimeException, xml::sax::SAXException)
1431 {
1432     OOXMLPropertySet::Pointer_t pPropSet(mpPropertySet->clone());
1433     OOXMLTableImpl::ValuePointer_t pTmpVal
1434         (new OOXMLPropertySetValue(pPropSet));
1435 
1436     mTable.add(pTmpVal);
1437 
1438     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1439 
1440 #ifdef DEBUG_PROPERTIES
1441     debug_logger->startElement("table");
1442     debug_logger->attribute("id", (*QNameToString::Instance())(mId));
1443     debug_logger->endElement("table");
1444 #endif
1445 
1446     mpStream->table(mId, pTable);
1447 
1448     endAction(Element);
1449 }
1450 
1451 /*
1452  class OOXMLFastContextHandlerValue
1453 */
1454 
OOXMLFastContextHandlerValue(OOXMLFastContextHandler * pContext)1455 OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue
1456 (OOXMLFastContextHandler * pContext)
1457 : OOXMLFastContextHandler(pContext)
1458 {
1459 }
1460 
~OOXMLFastContextHandlerValue()1461 OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue()
1462 {
1463 }
1464 
setValue(OOXMLValue::Pointer_t pValue)1465 void OOXMLFastContextHandlerValue::setValue(OOXMLValue::Pointer_t pValue)
1466 {
1467 #ifdef DEBUG_CONTEXT_HANDLER
1468     debug_logger->startElement("contexthandler.setValue");
1469     debug_logger->attribute("value", pValue->toString());
1470 #endif
1471 
1472     mpValue = pValue;
1473 
1474 #ifdef DEBUG_CONTEXT_HANDLER
1475     debug_logger->endElement("contexthandler.setValue");
1476 #endif
1477 }
1478 
getValue() const1479 OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const
1480 {
1481     return mpValue;
1482 }
1483 
lcl_endFastElement(Token_t Element)1484 void OOXMLFastContextHandlerValue::lcl_endFastElement
1485 (Token_t Element)
1486 throw (uno::RuntimeException, xml::sax::SAXException)
1487 {
1488     sendPropertyToParent();
1489 
1490     endAction(Element);
1491 }
1492 
setDefaultBooleanValue()1493 void OOXMLFastContextHandlerValue::setDefaultBooleanValue()
1494 {
1495 #ifdef DEBUG_ELEMENT
1496     debug_logger->element("setDefaultBooleanValue");
1497 #endif
1498 
1499     if (mpValue.get() == NULL)
1500     {
1501         OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(true));
1502         setValue(pValue);
1503     }
1504 }
1505 
setDefaultIntegerValue()1506 void OOXMLFastContextHandlerValue::setDefaultIntegerValue()
1507 {
1508 #ifdef DEBUG_ELEMENT
1509     debug_logger->element("setDefaultIntegerValue");
1510 #endif
1511 
1512     if (mpValue.get() == NULL)
1513     {
1514         OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(0));
1515         setValue(pValue);
1516     }
1517 }
1518 
setDefaultHexValue()1519 void OOXMLFastContextHandlerValue::setDefaultHexValue()
1520 {
1521 #ifdef DEBUG_ELEMENT
1522     debug_logger->element("setDefaultHexValue");
1523 #endif
1524 
1525     if (mpValue.get() == NULL)
1526     {
1527         OOXMLValue::Pointer_t pValue(new OOXMLHexValue(0));
1528         setValue(pValue);
1529     }
1530 }
1531 
setDefaultStringValue()1532 void OOXMLFastContextHandlerValue::setDefaultStringValue()
1533 {
1534 #ifdef DEBUG_ELEMENT
1535     debug_logger->element("setDefaultStringValue");
1536 #endif
1537 
1538     if (mpValue.get() == NULL)
1539     {
1540         OOXMLValue::Pointer_t pValue(new OOXMLStringValue(::rtl::OUString()));
1541         setValue(pValue);
1542     }
1543 }
1544 /*
1545   class OOXMLFastContextHandlerTable
1546 */
1547 
OOXMLFastContextHandlerTable(OOXMLFastContextHandler * pContext)1548 OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable
1549 (OOXMLFastContextHandler * pContext)
1550 : OOXMLFastContextHandler(pContext)
1551 {
1552 }
1553 
~OOXMLFastContextHandlerTable()1554 OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable()
1555 {
1556 }
1557 
1558 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1559 OOXMLFastContextHandlerTable::createFastChildContext
1560 (Token_t Element,
1561  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1562     throw (uno::RuntimeException, xml::sax::SAXException)
1563 {
1564     addCurrentChild();
1565 
1566     mCurrentChild.set
1567         (OOXMLFastContextHandler::createFastChildContext(Element, Attribs));
1568 
1569     return mCurrentChild;
1570 }
1571 
lcl_endFastElement(Token_t)1572 void OOXMLFastContextHandlerTable::lcl_endFastElement
1573 (Token_t /*Element*/)
1574     throw (uno::RuntimeException, xml::sax::SAXException)
1575 {
1576     addCurrentChild();
1577 
1578     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1579     if (isForwardEvents() && mId != 0x0)
1580     {
1581 #ifdef DEBUG_PROPERTIES
1582         debug_logger->startElement("table");
1583         string str = (*QNameToString::Instance())(mId);
1584         debug_logger->attribute("id", str);
1585         debug_logger->endElement("table");
1586 #endif
1587 
1588         mpStream->table(mId, pTable);
1589     }
1590 }
1591 
addCurrentChild()1592 void OOXMLFastContextHandlerTable::addCurrentChild()
1593 {
1594     OOXMLFastContextHandler * pHandler = mCurrentChild.getPointer();
1595     if ( pHandler != NULL)
1596     {
1597         OOXMLValue::Pointer_t pValue(pHandler->getValue());
1598 
1599         if (pValue.get() != NULL)
1600         {
1601             OOXMLTableImpl::ValuePointer_t pTmpVal(pValue->clone());
1602             mTable.add(pTmpVal);
1603         }
1604     }
1605 }
1606 
newPropertySet(OOXMLPropertySet::Pointer_t)1607 void OOXMLFastContextHandlerTable::newPropertySet
1608 (OOXMLPropertySet::Pointer_t /*pPropertySet*/)
1609 {
1610 
1611 }
1612 
1613 /*
1614   class OOXMLFastContextHandlerXNote
1615  */
1616 
OOXMLFastContextHandlerXNote(OOXMLFastContextHandler * pContext)1617 OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote
1618     ( OOXMLFastContextHandler * pContext )
1619     : OOXMLFastContextHandlerProperties( pContext )
1620     , mbForwardEventsSaved( false )
1621     , mnMyXNoteId( -1 )
1622 {
1623 }
1624 
~OOXMLFastContextHandlerXNote()1625 OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote()
1626 {
1627 }
1628 
lcl_startFastElement(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> &)1629 void OOXMLFastContextHandlerXNote::lcl_startFastElement
1630 (Token_t Element,
1631  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1632     throw (uno::RuntimeException, xml::sax::SAXException)
1633 {
1634     mbForwardEventsSaved = isForwardEvents();
1635 
1636     if ( mnMyXNoteId == mpParserState->getDocument()->getIDForXNoteStream() )
1637         setForwardEvents(true);
1638     else
1639         setForwardEvents(false);
1640 
1641     startAction(Element);
1642 }
1643 
lcl_endFastElement(Token_t Element)1644 void OOXMLFastContextHandlerXNote::lcl_endFastElement
1645 (Token_t Element)
1646     throw (uno::RuntimeException, xml::sax::SAXException)
1647 {
1648     // handle properties by calling parent class' method
1649     OOXMLFastContextHandlerProperties::lcl_endFastElement( Element );
1650 
1651     setForwardEvents(mbForwardEventsSaved);
1652 }
1653 
checkId(OOXMLValue::Pointer_t pValue)1654 void OOXMLFastContextHandlerXNote::checkId(OOXMLValue::Pointer_t pValue)
1655 {
1656 #ifdef DEBUG_ELEMENT
1657     debug_logger->startElement("checkId");
1658     debug_logger->attribute("myId", pValue->getInt());
1659     debug_logger->attribute("id", mpParserState->getDocument()->getXNoteId());
1660     debug_logger->endElement("checkId");
1661 #endif
1662 
1663     mnMyXNoteId = pValue->getInt();
1664 }
1665 
1666 /*
1667   class OOXMLFastContextHandlerTextTableCell
1668  */
1669 
OOXMLFastContextHandlerTextTableCell(OOXMLFastContextHandler * pContext)1670 OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell
1671 (OOXMLFastContextHandler * pContext)
1672 : OOXMLFastContextHandler(pContext)
1673 {
1674 }
1675 
~OOXMLFastContextHandlerTextTableCell()1676 OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
1677 {
1678 }
1679 
startCell()1680 void OOXMLFastContextHandlerTextTableCell::startCell()
1681 {
1682 }
1683 
endCell()1684 void OOXMLFastContextHandlerTextTableCell::endCell()
1685 {
1686     if (isForwardEvents())
1687     {
1688         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1689         {
1690             OOXMLValue::Pointer_t pVal
1691                 (new OOXMLIntegerValue(mnTableDepth));
1692             OOXMLProperty::Pointer_t pProp
1693                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
1694             pProps->add(pProp);
1695         }
1696         {
1697             OOXMLValue::Pointer_t pVal
1698                 (new OOXMLIntegerValue(1));
1699             OOXMLProperty::Pointer_t pProp
1700                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
1701             pProps->add(pProp);
1702         }
1703         {
1704             OOXMLValue::Pointer_t pVal
1705                 (new OOXMLBooleanValue(mnTableDepth > 0));
1706             OOXMLProperty::Pointer_t pProp
1707                 (new OOXMLPropertyImpl(NS_sprm::LN_PCell, pVal, OOXMLPropertyImpl::SPRM));
1708             pProps->add(pProp);
1709         }
1710 
1711 #ifdef DEBUG_PROPERTIES
1712         debug_logger->startElement("endcell");
1713         debug_logger->addTag(toPropertiesTag
1714                              (OOXMLPropertySet::Pointer_t(pProps->clone())));
1715         debug_logger->endElement("endcell");
1716 #endif
1717         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1718     }
1719 }
1720 
1721 /*
1722   class OOXMLFastContextHandlerTextTableRow
1723  */
1724 
OOXMLFastContextHandlerTextTableRow(OOXMLFastContextHandler * pContext)1725 OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow
1726 (OOXMLFastContextHandler * pContext)
1727 : OOXMLFastContextHandler(pContext)
1728 {
1729 }
1730 
~OOXMLFastContextHandlerTextTableRow()1731 OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow()
1732 {
1733 }
1734 
startRow()1735 void OOXMLFastContextHandlerTextTableRow::startRow()
1736 {
1737 }
1738 
endRow()1739 void OOXMLFastContextHandlerTextTableRow::endRow()
1740 {
1741     startParagraphGroup();
1742 
1743     if (isForwardEvents())
1744     {
1745         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1746         {
1747             OOXMLValue::Pointer_t pVal
1748                 (new OOXMLIntegerValue(mnTableDepth));
1749             OOXMLProperty::Pointer_t pProp
1750                 (new OOXMLPropertyImpl(NS_sprm::LN_PTableDepth, pVal, OOXMLPropertyImpl::SPRM));
1751             pProps->add(pProp);
1752         }
1753         {
1754             OOXMLValue::Pointer_t pVal
1755                 (new OOXMLIntegerValue(1));
1756             OOXMLProperty::Pointer_t pProp
1757                 (new OOXMLPropertyImpl(NS_sprm::LN_PFInTable, pVal, OOXMLPropertyImpl::SPRM));
1758             pProps->add(pProp);
1759         }
1760         {
1761             OOXMLValue::Pointer_t pVal
1762                 (new OOXMLIntegerValue(1));
1763             OOXMLProperty::Pointer_t pProp
1764                 (new OOXMLPropertyImpl(NS_sprm::LN_PRow, pVal, OOXMLPropertyImpl::SPRM));
1765             pProps->add(pProp);
1766         }
1767 
1768 #ifdef DEBUG_PROPERTIES
1769         debug_logger->startElement("endrow");
1770         debug_logger->addTag(toPropertiesTag
1771                              (OOXMLPropertySet::Pointer_t(pProps->clone())));
1772         debug_logger->endElement("endrow");
1773 #endif
1774 
1775         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1776     }
1777 
1778     startCharacterGroup();
1779 
1780     if (isForwardEvents())
1781         mpStream->utext(s0xd, 1);
1782 
1783     endCharacterGroup();
1784     endParagraphGroup();
1785 }
1786 
1787 /*
1788   class OOXMLFastContextHandlerTextTable
1789  */
1790 
OOXMLFastContextHandlerTextTable(OOXMLFastContextHandler * pContext)1791 OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable
1792 (OOXMLFastContextHandler * pContext)
1793 : OOXMLFastContextHandler(pContext)
1794 {
1795 }
1796 
~OOXMLFastContextHandlerTextTable()1797 OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable()
1798 {
1799     clearTableProps();
1800 }
1801 
lcl_startFastElement(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> &)1802 void OOXMLFastContextHandlerTextTable::lcl_startFastElement
1803 (Token_t Element,
1804  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1805     throw (uno::RuntimeException, xml::sax::SAXException)
1806 {
1807     mpParserState->startTable();
1808     mnTableDepth++;
1809 
1810     boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
1811     {
1812         OOXMLValue::Pointer_t pVal
1813             (new OOXMLIntegerValue(mnTableDepth));
1814         OOXMLProperty::Pointer_t pProp
1815             (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart, pVal, OOXMLPropertyImpl::SPRM));
1816         pProps->add(pProp);
1817     }
1818     mpParserState->setCharacterProperties(pProps);
1819 
1820     startAction(Element);
1821 }
1822 
lcl_endFastElement(Token_t Element)1823 void OOXMLFastContextHandlerTextTable::lcl_endFastElement
1824 (Token_t Element)
1825     throw (uno::RuntimeException, xml::sax::SAXException)
1826 {
1827     endAction(Element);
1828 
1829     mnTableDepth--;
1830     mpParserState->endTable();
1831 }
1832 
1833 /*
1834   class OOXMLFastContextHandlerShape
1835  */
1836 
OOXMLFastContextHandlerShape(OOXMLFastContextHandler * pContext)1837 OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
1838 (OOXMLFastContextHandler * pContext)
1839 : OOXMLFastContextHandlerProperties(pContext), m_bShapeSent( false ),
1840     m_bShapeStarted(false)
1841 {
1842     uno::Reference<uno::XComponentContext> xContext(getComponentContext());
1843     if (xContext.is())
1844     {
1845         uno::Reference<XMultiComponentFactory> rServiceManager
1846             (xContext->getServiceManager());
1847 
1848         mrShapeContext.set
1849             (rServiceManager->
1850               createInstanceWithContext
1851               (::rtl::OUString
1852                (RTL_CONSTASCII_USTRINGPARAM
1853                 ("com.sun.star.xml.sax.FastShapeContextHandler")), xContext),
1854               uno::UNO_QUERY);
1855 
1856         if (mrShapeContext.is())
1857         {
1858             mrShapeContext->setModel(getDocument()->getModel());
1859             mrShapeContext->setDrawPage(getDocument()->getDrawPage());
1860             mrShapeContext->setInputStream(getDocument()->getStorageStream());
1861 
1862 #ifdef DEBUG_ELEMENT
1863             debug_logger->startElement("setRelationFragmentPath");
1864             debug_logger->attribute("path", mpParserState->getTarget());
1865             debug_logger->endElement("setRelationFragmentPath");
1866 #endif
1867             mrShapeContext->setRelationFragmentPath
1868                 (mpParserState->getTarget());
1869         }
1870 #ifdef DEBUG_CONTEXT_STACK
1871         else
1872         {
1873             debug_logger->startElement("error");
1874             debug_logger->chars("failed to get shape handler");
1875             debug_logger->endElement("error");
1876         }
1877 #endif
1878     }
1879 }
1880 
~OOXMLFastContextHandlerShape()1881 OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape()
1882 {
1883 }
1884 
lcl_startFastElement(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1885 void OOXMLFastContextHandlerShape::lcl_startFastElement
1886 (Token_t Element,
1887  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1888     throw (uno::RuntimeException, xml::sax::SAXException)
1889 {
1890     startAction(Element);
1891 
1892     if (mrShapeContext.is())
1893     {
1894         mrShapeContext->startFastElement(Element, Attribs);
1895     }
1896 }
1897 
startUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1898 void SAL_CALL OOXMLFastContextHandlerShape::startUnknownElement
1899 (const ::rtl::OUString & Namespace,
1900  const ::rtl::OUString & Name,
1901  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1902     throw (uno::RuntimeException, xml::sax::SAXException)
1903 {
1904     if (mrShapeContext.is())
1905         mrShapeContext->startUnknownElement(Namespace, Name, Attribs);
1906 }
1907 
setToken(Token_t nToken)1908 void OOXMLFastContextHandlerShape::setToken(Token_t nToken)
1909 {
1910     OOXMLFastContextHandler::setToken(nToken);
1911 
1912     if (mrShapeContext.is())
1913         mrShapeContext->setStartToken(nToken);
1914 }
1915 
sendShape(Token_t Element)1916 void OOXMLFastContextHandlerShape::sendShape( Token_t Element )
1917 {
1918     if ( mrShapeContext.is() && !m_bShapeSent )
1919     {
1920         uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape());
1921         if (xShape.is())
1922         {
1923             OOXMLValue::Pointer_t
1924                 pValue(new OOXMLShapeValue(xShape));
1925             newProperty(NS_ooxml::LN_shape, pValue);
1926             m_bShapeSent = true;
1927 
1928             bool bIsPicture = Element == ( NS_picture | OOXML_pic );
1929 
1930             // Notify the dmapper that the shape is ready to use
1931             if ( !bIsPicture )
1932             {
1933                 mpStream->startShape( xShape );
1934                 m_bShapeStarted = true;
1935             }
1936         }
1937     }
1938 }
1939 
lcl_endFastElement(Token_t Element)1940 void OOXMLFastContextHandlerShape::lcl_endFastElement
1941 (Token_t Element)
1942     throw (uno::RuntimeException, xml::sax::SAXException)
1943 {
1944     if (mrShapeContext.is())
1945     {
1946         mrShapeContext->endFastElement(Element);
1947         sendShape( Element );
1948     }
1949 
1950     OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
1951 
1952     // Ending the shape should be the last thing to do
1953     bool bIsPicture = Element == ( NS_picture | OOXML_pic );
1954     if ( !bIsPicture && m_bShapeStarted)
1955         mpStream->endShape( );
1956 }
1957 
endUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name)1958 void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement
1959 (const ::rtl::OUString & Namespace,
1960  const ::rtl::OUString & Name)
1961     throw (uno::RuntimeException, xml::sax::SAXException)
1962 {
1963     if (mrShapeContext.is())
1964         mrShapeContext->endUnknownElement(Namespace, Name);
1965 }
1966 
1967 uno::Reference< xml::sax::XFastContextHandler >
lcl_createFastChildContext(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)1968 OOXMLFastContextHandlerShape::lcl_createFastChildContext
1969 (Token_t Element,
1970  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1971     throw (uno::RuntimeException, xml::sax::SAXException)
1972 {
1973     uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
1974 
1975     sal_uInt32 nNamespace = Element & 0xffff0000;
1976 
1977     switch (nNamespace)
1978     {
1979         case NS_wordprocessingml:
1980         case NS_vml_wordprocessingDrawing:
1981         case NS_office:
1982             xContextHandler.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
1983             break;
1984         default:
1985             if (mrShapeContext.is())
1986             {
1987                 uno::Reference<XFastContextHandler> pChildContext =
1988                 mrShapeContext->createFastChildContext(Element, Attribs);
1989 
1990                 OOXMLFastContextHandlerWrapper * pWrapper =
1991                 new OOXMLFastContextHandlerWrapper(this, pChildContext);
1992 
1993                 pWrapper->addNamespace(NS_wordprocessingml);
1994                 pWrapper->addNamespace(NS_vml_wordprocessingDrawing);
1995                 pWrapper->addNamespace(NS_office);
1996                 pWrapper->addToken( NS_vml|OOXML_textbox );
1997 
1998                 xContextHandler.set(pWrapper);
1999             }
2000             else
2001                 xContextHandler.set(this);
2002             break;
2003     }
2004 
2005 
2006     return xContextHandler;
2007 }
2008 
2009 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2010 OOXMLFastContextHandlerShape::createUnknownChildContext
2011 (const ::rtl::OUString & Namespace,
2012  const ::rtl::OUString & Name,
2013  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2014     throw (uno::RuntimeException, xml::sax::SAXException)
2015 {
2016     uno::Reference< xml::sax::XFastContextHandler > xResult;
2017 
2018     if (mrShapeContext.is())
2019         xResult.set(mrShapeContext->createUnknownChildContext
2020             (Namespace, Name, Attribs));
2021 
2022     return xResult;
2023 }
2024 
lcl_characters(const::rtl::OUString & aChars)2025 void OOXMLFastContextHandlerShape::lcl_characters
2026 (const ::rtl::OUString & aChars)
2027     throw (uno::RuntimeException, xml::sax::SAXException)
2028 {
2029     if (mrShapeContext.is())
2030         mrShapeContext->characters(aChars);
2031 }
2032 
2033 /*
2034   class OOXMLFastContextHandlerWrapper
2035 */
2036 
OOXMLFastContextHandlerWrapper(OOXMLFastContextHandler * pParent,uno::Reference<XFastContextHandler> xContext)2037 OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper
2038 (OOXMLFastContextHandler * pParent,
2039  uno::Reference<XFastContextHandler> xContext)
2040 : OOXMLFastContextHandler(pParent), mxContext(xContext)
2041 {
2042     if (pParent != NULL)
2043     {
2044         setId(pParent->getId());
2045         setToken(pParent->getToken());
2046         setPropertySet(pParent->getPropertySet());
2047     }
2048 }
2049 
~OOXMLFastContextHandlerWrapper()2050 OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper()
2051 {
2052 }
2053 
startUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2054 void SAL_CALL OOXMLFastContextHandlerWrapper::startUnknownElement
2055 (const ::rtl::OUString & Namespace,
2056  const ::rtl::OUString & Name,
2057  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2058     throw (uno::RuntimeException, xml::sax::SAXException)
2059 {
2060     if (mxContext.is())
2061         mxContext->startUnknownElement(Namespace, Name, Attribs);
2062 }
2063 
endUnknownElement(const::rtl::OUString & Namespace,const::rtl::OUString & Name)2064 void SAL_CALL OOXMLFastContextHandlerWrapper::endUnknownElement
2065 (const ::rtl::OUString & Namespace,
2066  const ::rtl::OUString & Name)
2067     throw (uno::RuntimeException, xml::sax::SAXException)
2068 {
2069     if (mxContext.is())
2070         mxContext->endUnknownElement(Namespace, Name);
2071 }
2072 
2073 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString & Namespace,const::rtl::OUString & Name,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2074 OOXMLFastContextHandlerWrapper::createUnknownChildContext
2075 (const ::rtl::OUString & Namespace,
2076  const ::rtl::OUString & Name,
2077  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2078     throw (uno::RuntimeException, xml::sax::SAXException)
2079 {
2080     uno::Reference< xml::sax::XFastContextHandler > xResult;
2081 
2082     if (mxContext.is())
2083         xResult = mxContext->createUnknownChildContext
2084             (Namespace, Name, Attribs);
2085     else
2086         xResult.set(this);
2087 
2088     return xResult;
2089 }
2090 
attributes(const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2091 void OOXMLFastContextHandlerWrapper::attributes
2092 (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2093 throw (uno::RuntimeException, xml::sax::SAXException)
2094 {
2095     if (mxContext.is())
2096     {
2097         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2098         if (pHandler != NULL)
2099             pHandler->attributes(Attribs);
2100     }
2101 }
2102 
2103 OOXMLFastContextHandler::ResourceEnum_t
getResource() const2104 OOXMLFastContextHandlerWrapper::getResource() const
2105 {
2106     return UNKNOWN;
2107 }
2108 
addNamespace(const Id & nId)2109 void OOXMLFastContextHandlerWrapper::addNamespace(const Id & nId)
2110 {
2111     mMyNamespaces.insert(nId);
2112 }
2113 
addToken(Token_t Token)2114 void OOXMLFastContextHandlerWrapper::addToken( Token_t Token )
2115 {
2116     mMyTokens.insert( Token );
2117 }
2118 
lcl_startFastElement(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2119 void OOXMLFastContextHandlerWrapper::lcl_startFastElement
2120 (Token_t Element,
2121  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2122     throw (uno::RuntimeException, xml::sax::SAXException)
2123 {
2124     if (mxContext.is())
2125         mxContext->startFastElement(Element, Attribs);
2126 }
2127 
lcl_endFastElement(Token_t Element)2128 void OOXMLFastContextHandlerWrapper::lcl_endFastElement
2129 (Token_t Element)
2130     throw (uno::RuntimeException, xml::sax::SAXException)
2131 {
2132     if (mxContext.is())
2133         mxContext->endFastElement(Element);
2134 }
2135 
2136 uno::Reference< xml::sax::XFastContextHandler >
lcl_createFastChildContext(Token_t Element,const uno::Reference<xml::sax::XFastAttributeList> & Attribs)2137 OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
2138 (Token_t Element,
2139  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
2140     throw (uno::RuntimeException, xml::sax::SAXException)
2141 {
2142     uno::Reference< xml::sax::XFastContextHandler > xResult;
2143 
2144     Id nNameSpace = Element & 0xffff0000;
2145 
2146 #ifdef DEBUG_ELEMENT
2147     debug_logger->startElement("Wrapper-createChildContext");
2148     debug_logger->attribute("token", fastTokenToId(Element));
2149 
2150     set<Id>::const_iterator aIt(mMyNamespaces.begin());
2151     while (aIt != mMyNamespaces.end())
2152     {
2153         debug_logger->startElement("namespace");
2154         debug_logger->attribute("id", fastTokenToId(*aIt));
2155         debug_logger->endElement("namespace");
2156 
2157         aIt++;
2158     }
2159 
2160     debug_logger->endElement("Wrapper-createChildContext");
2161 #endif
2162 
2163     bool bInNamespaces = mMyNamespaces.find(nNameSpace) != mMyNamespaces.end();
2164     bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( );
2165     if ( bInNamespaces )
2166         xResult.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
2167     else if (mxContext.is())
2168     {
2169         OOXMLFastContextHandlerWrapper * pWrapper =
2170             new OOXMLFastContextHandlerWrapper
2171             (this, mxContext->createFastChildContext(Element, Attribs));
2172         pWrapper->mMyNamespaces = mMyNamespaces;
2173         pWrapper->setPropertySet(getPropertySet());
2174         xResult.set(pWrapper);
2175     }
2176     else
2177         xResult.set(this);
2178 
2179     if ( bInTokens )
2180     {
2181         OOXMLFastContextHandlerShape* pShapeCtx = (OOXMLFastContextHandlerShape*)mpParent;
2182         pShapeCtx->sendShape( Element );
2183     }
2184 
2185     return xResult;
2186 }
2187 
lcl_characters(const::rtl::OUString & aChars)2188 void OOXMLFastContextHandlerWrapper::lcl_characters
2189 (const ::rtl::OUString & aChars)
2190     throw (uno::RuntimeException, xml::sax::SAXException)
2191 {
2192     if (mxContext.is())
2193         mxContext->characters(aChars);
2194 }
2195 
2196 OOXMLFastContextHandler *
getFastContextHandler() const2197 OOXMLFastContextHandlerWrapper::getFastContextHandler() const
2198 {
2199     if (mxContext.is())
2200         return dynamic_cast<OOXMLFastContextHandler *>(mxContext.get());
2201 
2202     return NULL;
2203 }
2204 
newProperty(const Id & rId,OOXMLValue::Pointer_t pVal)2205 void OOXMLFastContextHandlerWrapper::newProperty
2206 (const Id & rId, OOXMLValue::Pointer_t pVal)
2207 {
2208     if (mxContext.is())
2209     {
2210         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2211         if (pHandler != NULL)
2212             pHandler->newProperty(rId, pVal);
2213     }
2214 }
2215 
setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet)2216 void OOXMLFastContextHandlerWrapper::setPropertySet
2217 (OOXMLPropertySet::Pointer_t pPropertySet)
2218 {
2219     if (mxContext.is())
2220     {
2221         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2222         if (pHandler != NULL)
2223             pHandler->setPropertySet(pPropertySet);
2224     }
2225 
2226     mpPropertySet = pPropertySet;
2227 }
2228 
getPropertySet() const2229 OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerWrapper::getPropertySet()
2230     const
2231 {
2232     OOXMLPropertySet::Pointer_t pResult(mpPropertySet);
2233 
2234     if (mxContext.is())
2235     {
2236         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2237         if (pHandler != NULL)
2238             pResult = pHandler->getPropertySet();
2239     }
2240 
2241     return pResult;
2242 }
2243 
getType() const2244 string OOXMLFastContextHandlerWrapper::getType() const
2245 {
2246     string sResult = "Wrapper(";
2247 
2248     if (mxContext.is())
2249     {
2250         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2251         if (pHandler != NULL)
2252             sResult += pHandler->getType();
2253     }
2254 
2255     sResult += ")";
2256 
2257     return sResult;
2258 }
2259 
setId(Id rId)2260 void OOXMLFastContextHandlerWrapper::setId(Id rId)
2261 {
2262     OOXMLFastContextHandler::setId(rId);
2263 
2264     if (mxContext.is())
2265     {
2266         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2267         if (pHandler != NULL)
2268             pHandler->setId(rId);
2269     }
2270 }
2271 
getId() const2272 Id OOXMLFastContextHandlerWrapper::getId() const
2273 {
2274     Id nResult = OOXMLFastContextHandler::getId();
2275 
2276     if (mxContext.is())
2277     {
2278         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2279         if (pHandler != NULL && pHandler->getId() != 0)
2280             nResult = pHandler->getId();
2281     }
2282 
2283     return nResult;
2284 }
2285 
setToken(Token_t nToken)2286 void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken)
2287 {
2288     OOXMLFastContextHandler::setToken(nToken);
2289 
2290     if (mxContext.is())
2291     {
2292         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2293         if (pHandler != NULL)
2294             pHandler->setToken(nToken);
2295     }
2296 }
2297 
getToken() const2298 Token_t OOXMLFastContextHandlerWrapper::getToken() const
2299 {
2300     Token_t nResult = OOXMLFastContextHandler::getToken();
2301 
2302     if (mxContext.is())
2303     {
2304         OOXMLFastContextHandler * pHandler = getFastContextHandler();
2305         if (pHandler != NULL)
2306             nResult = pHandler->getToken();
2307     }
2308 
2309     return nResult;
2310 }
2311 
2312 }}
2313