xref: /AOO41X/main/xmloff/source/draw/XMLImageMapContext.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLImageMapContext.hxx"
27 #include <rtl/ustrbuf.hxx>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP
31 #include <com/sun/star/beans/XPropertySetInfo.hpp>
32 #endif
33 #include <com/sun/star/xml/sax/XAttributeList.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
37 
38 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
39 #include <com/sun/star/document/XEventsSupplier.hpp>
40 #endif
41 #include <com/sun/star/awt/Rectangle.hpp>
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmlimp.hxx>
44 #include <xmloff/xmltkmap.hxx>
45 #include "xmloff/xmlnmspe.hxx"
46 #include <xmloff/nmspmap.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include "xexptran.hxx"
49 #include "xmloff/xmlerror.hxx"
50 #include <xmloff/XMLEventsImportContext.hxx>
51 #include "XMLStringBufferImportContext.hxx"
52 #include <tools/debug.hxx>
53 
54 
55 using namespace ::com::sun::star;
56 using namespace ::xmloff::token;
57 
58 using ::rtl::OUString;
59 using ::rtl::OUStringBuffer;
60 using ::com::sun::star::beans::XPropertySet;
61 using ::com::sun::star::beans::XPropertySetInfo;
62 using ::com::sun::star::container::XIndexContainer;
63 using ::com::sun::star::lang::XMultiServiceFactory;
64 using ::com::sun::star::uno::Reference;
65 using ::com::sun::star::uno::UNO_QUERY;
66 using ::com::sun::star::xml::sax::XAttributeList;
67 using ::com::sun::star::uno::XInterface;
68 using ::com::sun::star::uno::Any;
69 using ::com::sun::star::drawing::PointSequenceSequence;
70 using ::com::sun::star::document::XEventsSupplier;
71 
72 
73 enum XMLImageMapToken
74 {
75     XML_TOK_IMAP_URL,
76     XML_TOK_IMAP_X,
77     XML_TOK_IMAP_Y,
78     XML_TOK_IMAP_CENTER_X,
79     XML_TOK_IMAP_CENTER_Y,
80     XML_TOK_IMAP_WIDTH,
81     XML_TOK_IMAP_HEIGTH,
82     XML_TOK_IMAP_POINTS,
83     XML_TOK_IMAP_VIEWBOX,
84     XML_TOK_IMAP_NOHREF,
85     XML_TOK_IMAP_NAME,
86     XML_TOK_IMAP_RADIUS,
87     XML_TOK_IMAP_TARGET
88 };
89 
90 static __FAR_DATA SvXMLTokenMapEntry aImageMapObjectTokenMap[] =
91 {
92     { XML_NAMESPACE_XLINK,  XML_HREF,           XML_TOK_IMAP_URL            },
93     { XML_NAMESPACE_OFFICE, XML_NAME,           XML_TOK_IMAP_NAME           },
94     { XML_NAMESPACE_DRAW,   XML_NOHREF,         XML_TOK_IMAP_NOHREF         },
95     { XML_NAMESPACE_SVG,    XML_X,              XML_TOK_IMAP_X              },
96     { XML_NAMESPACE_SVG,    XML_Y,              XML_TOK_IMAP_Y              },
97     { XML_NAMESPACE_SVG,    XML_CX,             XML_TOK_IMAP_CENTER_X       },
98     { XML_NAMESPACE_SVG,    XML_CY,             XML_TOK_IMAP_CENTER_Y       },
99     { XML_NAMESPACE_SVG,    XML_WIDTH,          XML_TOK_IMAP_WIDTH          },
100     { XML_NAMESPACE_SVG,    XML_HEIGHT,         XML_TOK_IMAP_HEIGTH         },
101     { XML_NAMESPACE_SVG,    XML_R,              XML_TOK_IMAP_RADIUS         },
102     { XML_NAMESPACE_SVG,    XML_VIEWBOX,        XML_TOK_IMAP_VIEWBOX        },
103     { XML_NAMESPACE_DRAW,   XML_POINTS,         XML_TOK_IMAP_POINTS         },
104     { XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, XML_TOK_IMAP_TARGET      },
105     XML_TOKEN_MAP_END
106 };
107 
108 
109 
110 class XMLImageMapObjectContext : public SvXMLImportContext
111 {
112 
113 protected:
114 
115     const ::rtl::OUString sBoundary;
116     const ::rtl::OUString sCenter;
117     const ::rtl::OUString sTitle;
118     const ::rtl::OUString sDescription;
119     const ::rtl::OUString sImageMap;
120     const ::rtl::OUString sIsActive;
121     const ::rtl::OUString sName;
122     const ::rtl::OUString sPolygon;
123     const ::rtl::OUString sRadius;
124     const ::rtl::OUString sTarget;
125     const ::rtl::OUString sURL;
126 
127     ::rtl::OUString sServiceName;
128 
129     Reference<XIndexContainer> xImageMap;   /// the image map
130     Reference<XPropertySet> xMapEntry;      /// one map-entry (one area)
131 
132     ::rtl::OUString sUrl;
133     ::rtl::OUString sTargt;
134     ::rtl::OUStringBuffer sDescriptionBuffer;
135     ::rtl::OUStringBuffer sTitleBuffer;
136     ::rtl::OUString sNam;
137     sal_Bool bIsActive;
138 
139     sal_Bool bValid;
140 
141 public:
142     TYPEINFO();
143 
144     XMLImageMapObjectContext(
145         SvXMLImport& rImport,
146         sal_uInt16 nPrefix,
147         const ::rtl::OUString& rLocalName,
148         ::com::sun::star::uno::Reference<
149             ::com::sun::star::container::XIndexContainer> xMap,
150         const sal_Char* pServiceName);
151 
152     void StartElement(
153         const ::com::sun::star::uno::Reference<
154         ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
155 
156     void EndElement();
157 
158     SvXMLImportContext *CreateChildContext(
159         sal_uInt16 nPrefix,
160         const ::rtl::OUString& rLocalName,
161         const ::com::sun::star::uno::Reference<
162             ::com::sun::star::xml::sax::XAttributeList> & xAttrList );
163 
164 protected:
165 
166     virtual void ProcessAttribute(
167         enum XMLImageMapToken eToken,
168         const ::rtl::OUString& rValue);
169 
170     virtual void Prepare(
171         ::com::sun::star::uno::Reference<
172             ::com::sun::star::beans::XPropertySet> & rPropertySet);
173 };
174 
175 
176 TYPEINIT1( XMLImageMapObjectContext, SvXMLImportContext );
177 
178 XMLImageMapObjectContext::XMLImageMapObjectContext(
179     SvXMLImport& rImport,
180     sal_uInt16 nPrefix,
181     const OUString& rLocalName,
182     Reference<XIndexContainer> xMap,
183     const sal_Char* pServiceName) :
184         SvXMLImportContext(rImport, nPrefix, rLocalName),
185         sBoundary(RTL_CONSTASCII_USTRINGPARAM("Boundary")),
186         sCenter(RTL_CONSTASCII_USTRINGPARAM("Center")),
187         sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")),
188         sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")),
189         sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")),
190         sIsActive(RTL_CONSTASCII_USTRINGPARAM("IsActive")),
191         sName(RTL_CONSTASCII_USTRINGPARAM("Name")),
192         sPolygon(RTL_CONSTASCII_USTRINGPARAM("Polygon")),
193         sRadius(RTL_CONSTASCII_USTRINGPARAM("Radius")),
194         sTarget(RTL_CONSTASCII_USTRINGPARAM("Target")),
195         sURL(RTL_CONSTASCII_USTRINGPARAM("URL")),
196         xImageMap(xMap),
197         bIsActive(sal_True),
198         bValid(sal_False)
199 {
200     DBG_ASSERT(NULL != pServiceName,
201                "Please supply the image map object service name");
202 
203     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
204     if( xFactory.is() )
205     {
206         Reference<XInterface> xIfc = xFactory->createInstance(
207             OUString::createFromAscii(pServiceName));
208         DBG_ASSERT(xIfc.is(), "can't create image map object!");
209         if( xIfc.is() )
210         {
211             Reference<XPropertySet> xPropertySet( xIfc, UNO_QUERY );
212 
213             xMapEntry = xPropertySet;
214         }
215         // else: can't create service -> ignore
216     }
217     // else: can't even get factory -> ignore
218 }
219 
220 void XMLImageMapObjectContext::StartElement(
221     const Reference<XAttributeList >& xAttrList )
222 {
223     SvXMLTokenMap aMap(aImageMapObjectTokenMap);
224 
225     sal_Int16 nLength = xAttrList->getLength();
226     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
227     {
228         OUString sLocalName;
229         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
230             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
231                               &sLocalName );
232         OUString sValue = xAttrList->getValueByIndex(nAttr);
233 
234         ProcessAttribute(
235             (enum XMLImageMapToken)aMap.Get(nPrefix, sLocalName), sValue);
236     }
237 }
238 
239 void XMLImageMapObjectContext::EndElement()
240 {
241     // only create and insert image map object if validity flag is set
242     // (and we actually have an image map)
243     if ( bValid && xImageMap.is() && xMapEntry.is() )
244     {
245         // set values
246         Prepare( xMapEntry );
247 
248         // insert into image map
249         Any aAny;
250         aAny <<= xMapEntry;
251         xImageMap->insertByIndex( xImageMap->getCount(), aAny );
252     }
253     // else: not valid -> don't create and insert
254 }
255 
256 SvXMLImportContext* XMLImageMapObjectContext::CreateChildContext(
257     sal_uInt16 nPrefix,
258     const OUString& rLocalName,
259     const Reference<XAttributeList> & xAttrList )
260 {
261     if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
262          IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
263     {
264         Reference<XEventsSupplier> xEvents( xMapEntry, UNO_QUERY );
265         return new XMLEventsImportContext(
266             GetImport(), nPrefix, rLocalName, xEvents);
267     }
268     else if ( (XML_NAMESPACE_SVG == nPrefix) &&
269               IsXMLToken(rLocalName, XML_TITLE) )
270     {
271         return new XMLStringBufferImportContext(
272             GetImport(), nPrefix, rLocalName, sTitleBuffer);
273     }
274     else if ( (XML_NAMESPACE_SVG == nPrefix) &&
275               IsXMLToken(rLocalName, XML_DESC) )
276     {
277         return new XMLStringBufferImportContext(
278             GetImport(), nPrefix, rLocalName, sDescriptionBuffer);
279     }
280     else
281         return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
282                                                       xAttrList);
283 
284 }
285 
286 void XMLImageMapObjectContext::ProcessAttribute(
287     enum XMLImageMapToken eToken,
288     const OUString& rValue)
289 {
290     switch (eToken)
291     {
292         case XML_TOK_IMAP_URL:
293             sUrl = GetImport().GetAbsoluteReference(rValue);
294             break;
295 
296         case XML_TOK_IMAP_TARGET:
297             sTargt = rValue;
298             break;
299 
300         case XML_TOK_IMAP_NOHREF:
301             bIsActive = ! IsXMLToken(rValue, XML_NOHREF);
302             break;
303 
304         case XML_TOK_IMAP_NAME:
305             sNam = rValue;
306             break;
307         default:
308             // do nothing
309             break;
310     }
311 }
312 
313 void XMLImageMapObjectContext::Prepare(
314     Reference<XPropertySet> & rPropertySet)
315 {
316     rPropertySet->setPropertyValue( sURL, Any( sUrl ) );
317     rPropertySet->setPropertyValue( sTitle, Any( sTitleBuffer.makeStringAndClear() ) );
318     rPropertySet->setPropertyValue( sDescription, Any( sDescriptionBuffer.makeStringAndClear() ) );
319     rPropertySet->setPropertyValue( sTarget, Any( sTargt ) );
320     rPropertySet->setPropertyValue( sIsActive, Any( bIsActive ) );
321     rPropertySet->setPropertyValue( sName, Any( sNam ) );
322 }
323 
324 
325 
326 class XMLImageMapRectangleContext : public XMLImageMapObjectContext
327 {
328     awt::Rectangle aRectangle;
329 
330     sal_Bool bXOK;
331     sal_Bool bYOK;
332     sal_Bool bWidthOK;
333     sal_Bool bHeightOK;
334 
335 public:
336     TYPEINFO();
337 
338     XMLImageMapRectangleContext(
339         SvXMLImport& rImport,
340         sal_uInt16 nPrefix,
341         const ::rtl::OUString& rLocalName,
342         ::com::sun::star::uno::Reference<
343             ::com::sun::star::container::XIndexContainer> xMap);
344 
345     virtual ~XMLImageMapRectangleContext();
346 
347 protected:
348     virtual void ProcessAttribute(
349         enum XMLImageMapToken eToken,
350         const ::rtl::OUString& rValue);
351 
352     virtual void Prepare(
353         ::com::sun::star::uno::Reference<
354             ::com::sun::star::beans::XPropertySet> & rPropertySet);
355 };
356 
357 
358 
359 TYPEINIT1(XMLImageMapRectangleContext, XMLImageMapObjectContext);
360 
361 XMLImageMapRectangleContext::XMLImageMapRectangleContext(
362     SvXMLImport& rImport,
363     sal_uInt16 nPrefix,
364     const OUString& rLocalName,
365     Reference<XIndexContainer> xMap) :
366         XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
367                                  "com.sun.star.image.ImageMapRectangleObject"),
368         bXOK(sal_False),
369         bYOK(sal_False),
370         bWidthOK(sal_False),
371         bHeightOK(sal_False)
372 {
373 }
374 
375 XMLImageMapRectangleContext::~XMLImageMapRectangleContext()
376 {
377 }
378 
379 void XMLImageMapRectangleContext::ProcessAttribute(
380     enum XMLImageMapToken eToken,
381     const OUString& rValue)
382 {
383     sal_Int32 nTmp;
384     switch (eToken)
385     {
386         case XML_TOK_IMAP_X:
387             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
388                                                                    rValue))
389             {
390                 aRectangle.X = nTmp;
391                 bXOK = sal_True;
392             }
393             break;
394         case XML_TOK_IMAP_Y:
395             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
396                                                                    rValue))
397             {
398                 aRectangle.Y = nTmp;
399                 bYOK = sal_True;
400             }
401             break;
402         case XML_TOK_IMAP_WIDTH:
403             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
404                                                                    rValue))
405             {
406                 aRectangle.Width = nTmp;
407                 bWidthOK = sal_True;
408             }
409             break;
410         case XML_TOK_IMAP_HEIGTH:
411             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
412                                                                    rValue))
413             {
414                 aRectangle.Height = nTmp;
415                 bHeightOK = sal_True;
416             }
417             break;
418         default:
419             XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
420     }
421 
422     bValid = bHeightOK && bXOK && bYOK && bWidthOK;
423 }
424 
425 void XMLImageMapRectangleContext::Prepare(
426     Reference<XPropertySet> & rPropertySet)
427 {
428     Any aAny;
429     aAny <<= aRectangle;
430     rPropertySet->setPropertyValue( sBoundary, aAny );
431 
432     // common properties handled by super class
433     XMLImageMapObjectContext::Prepare(rPropertySet);
434 }
435 
436 
437 class XMLImageMapPolygonContext : public XMLImageMapObjectContext
438 {
439     ::rtl::OUString sViewBoxString;
440     ::rtl::OUString sPointsString;
441 
442     sal_Bool bViewBoxOK;
443     sal_Bool bPointsOK;
444 
445 public:
446     TYPEINFO();
447 
448     XMLImageMapPolygonContext(
449         SvXMLImport& rImport,
450         sal_uInt16 nPrefix,
451         const ::rtl::OUString& rLocalName,
452         ::com::sun::star::uno::Reference<
453             ::com::sun::star::container::XIndexContainer> xMap);
454 
455     virtual ~XMLImageMapPolygonContext();
456 
457 protected:
458     virtual void ProcessAttribute(
459         enum XMLImageMapToken eToken,
460         const ::rtl::OUString& rValue);
461 
462     virtual void Prepare(
463         ::com::sun::star::uno::Reference<
464             ::com::sun::star::beans::XPropertySet> & rPropertySet);
465 };
466 
467 
468 
469 TYPEINIT1(XMLImageMapPolygonContext, XMLImageMapObjectContext);
470 
471 XMLImageMapPolygonContext::XMLImageMapPolygonContext(
472     SvXMLImport& rImport,
473     sal_uInt16 nPrefix,
474     const OUString& rLocalName,
475     Reference<XIndexContainer> xMap) :
476         XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
477                                  "com.sun.star.image.ImageMapPolygonObject"),
478         bViewBoxOK(sal_False),
479         bPointsOK(sal_False)
480 {
481 }
482 
483 XMLImageMapPolygonContext::~XMLImageMapPolygonContext()
484 {
485 }
486 
487 void XMLImageMapPolygonContext::ProcessAttribute(
488     enum XMLImageMapToken eToken,
489     const OUString& rValue)
490 {
491     switch (eToken)
492     {
493         case XML_TOK_IMAP_POINTS:
494             sPointsString = rValue;
495             bPointsOK = sal_True;
496             break;
497         case XML_TOK_IMAP_VIEWBOX:
498             sViewBoxString = rValue;
499             bViewBoxOK = sal_True;
500             break;
501         default:
502             XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
503             break;
504     }
505 
506     bValid = bViewBoxOK && bPointsOK;
507 }
508 
509 void XMLImageMapPolygonContext::Prepare(
510     Reference<XPropertySet> & rPropertySet)
511 {
512     // process view box
513     SdXMLImExViewBox aViewBox(sViewBoxString,
514                               GetImport().GetMM100UnitConverter());
515 
516     // get polygon sequence
517     awt::Point aPoint(aViewBox.GetX(), aViewBox.GetY());
518     awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
519     SdXMLImExPointsElement aPoints( sPointsString, aViewBox, aPoint, aSize,
520                                     GetImport().GetMM100UnitConverter() );
521     PointSequenceSequence aPointSeqSeq = aPoints.GetPointSequenceSequence();
522 
523     // only use first element of sequence-sequence
524     if (aPointSeqSeq.getLength() > 0)
525     {
526         Any aAny;
527         aAny <<= aPointSeqSeq[0];
528         rPropertySet->setPropertyValue(sPolygon, aAny);
529     }
530 
531     // parent properties
532     XMLImageMapObjectContext::Prepare(rPropertySet);
533 }
534 
535 
536 
537 class XMLImageMapCircleContext : public XMLImageMapObjectContext
538 {
539     awt::Point aCenter;
540     sal_Int32 nRadius;
541 
542     sal_Bool bXOK;
543     sal_Bool bYOK;
544     sal_Bool bRadiusOK;
545 
546 public:
547     TYPEINFO();
548 
549     XMLImageMapCircleContext(
550         SvXMLImport& rImport,
551         sal_uInt16 nPrefix,
552         const ::rtl::OUString& rLocalName,
553         ::com::sun::star::uno::Reference<
554             ::com::sun::star::container::XIndexContainer> xMap);
555 
556     virtual ~XMLImageMapCircleContext();
557 
558 protected:
559     virtual void ProcessAttribute(
560         enum XMLImageMapToken eToken,
561         const ::rtl::OUString& rValue);
562 
563     virtual void Prepare(
564         ::com::sun::star::uno::Reference<
565             ::com::sun::star::beans::XPropertySet> & rPropertySet);
566 };
567 
568 TYPEINIT1(XMLImageMapCircleContext, XMLImageMapObjectContext);
569 
570 XMLImageMapCircleContext::XMLImageMapCircleContext(
571     SvXMLImport& rImport,
572     sal_uInt16 nPrefix,
573     const OUString& rLocalName,
574     Reference<XIndexContainer> xMap) :
575         XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
576                                  "com.sun.star.image.ImageMapCircleObject"),
577         bXOK(sal_False),
578         bYOK(sal_False),
579         bRadiusOK(sal_False)
580 {
581 }
582 
583 XMLImageMapCircleContext::~XMLImageMapCircleContext()
584 {
585 }
586 
587 void XMLImageMapCircleContext::ProcessAttribute(
588     enum XMLImageMapToken eToken,
589     const OUString& rValue)
590 {
591     sal_Int32 nTmp;
592     switch (eToken)
593     {
594         case XML_TOK_IMAP_CENTER_X:
595             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
596                                                                    rValue))
597             {
598                 aCenter.X = nTmp;
599                 bXOK = sal_True;
600             }
601             break;
602         case XML_TOK_IMAP_CENTER_Y:
603             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
604                                                                    rValue))
605             {
606                 aCenter.Y = nTmp;
607                 bYOK = sal_True;
608             }
609             break;
610         case XML_TOK_IMAP_RADIUS:
611             if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp,
612                                                                    rValue))
613             {
614                 nRadius = nTmp;
615                 bRadiusOK = sal_True;
616             }
617             break;
618         default:
619             XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
620     }
621 
622     bValid = bRadiusOK && bXOK && bYOK;
623 }
624 
625 void XMLImageMapCircleContext::Prepare(
626     Reference<XPropertySet> & rPropertySet)
627 {
628     // center (x,y)
629     Any aAny;
630     aAny <<= aCenter;
631     rPropertySet->setPropertyValue( sCenter, aAny );
632 
633     // radius
634     aAny <<= nRadius;
635     rPropertySet->setPropertyValue( sRadius, aAny );
636 
637     // common properties handled by super class
638     XMLImageMapObjectContext::Prepare(rPropertySet);
639 }
640 
641 
642 
643 
644 
645 
646 
647 
648 
649 
650 TYPEINIT1(XMLImageMapContext, SvXMLImportContext);
651 
652 XMLImageMapContext::XMLImageMapContext(
653     SvXMLImport& rImport,
654     sal_uInt16 nPrefix,
655     const OUString& rLocalName,
656     Reference<XPropertySet> & rPropertySet) :
657         SvXMLImportContext(rImport, nPrefix, rLocalName),
658         sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")),
659         xPropertySet(rPropertySet)
660 
661 {
662     try
663     {
664         Reference < XPropertySetInfo > xInfo =
665             xPropertySet->getPropertySetInfo();
666         if( xInfo.is() && xInfo->hasPropertyByName( sImageMap ) )
667             xPropertySet->getPropertyValue(sImageMap) >>= xImageMap;
668     }
669     catch( com::sun::star::uno::Exception e )
670     {
671         uno::Sequence<OUString> aSeq(0);
672         rImport.SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
673     }
674 }
675 
676 XMLImageMapContext::~XMLImageMapContext()
677 {
678 }
679 
680 SvXMLImportContext *XMLImageMapContext::CreateChildContext(
681     sal_uInt16 nPrefix,
682     const OUString& rLocalName,
683     const Reference<XAttributeList> & xAttrList )
684 {
685     SvXMLImportContext* pContext = NULL;
686 
687     if ( XML_NAMESPACE_DRAW == nPrefix )
688     {
689         if ( IsXMLToken(rLocalName, XML_AREA_RECTANGLE) )
690         {
691             pContext = new XMLImageMapRectangleContext(
692                 GetImport(), nPrefix, rLocalName, xImageMap);
693         }
694         else if ( IsXMLToken(rLocalName, XML_AREA_POLYGON) )
695         {
696             pContext = new XMLImageMapPolygonContext(
697                 GetImport(), nPrefix, rLocalName, xImageMap);
698         }
699         else if ( IsXMLToken(rLocalName, XML_AREA_CIRCLE) )
700         {
701             pContext = new XMLImageMapCircleContext(
702                 GetImport(), nPrefix, rLocalName, xImageMap);
703         }
704     }
705     else
706         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
707                                                           xAttrList);
708 
709     return pContext;
710 }
711 
712 void XMLImageMapContext::EndElement()
713 {
714     Reference < XPropertySetInfo > xInfo =
715         xPropertySet->getPropertySetInfo();
716     if( xInfo.is() && xInfo->hasPropertyByName( sImageMap ) )
717         xPropertySet->setPropertyValue(sImageMap, uno::makeAny( xImageMap ) );
718 }
719 
720