Branch libreoffice-5-0-4
[LibreOffice.git] / framework / source / xml / imagesdocumenthandler.cxx
blobd78cd8f5abd818904825a66f48a91c61417ed7c2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
22 #include <xml/imagesdocumenthandler.hxx>
24 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
26 #include <vcl/svapp.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <rtl/ustrbuf.hxx>
30 #include <comphelper/attributelist.hxx>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
35 #define ELEMENT_IMAGECONTAINER "imagescontainer"
36 #define ELEMENT_IMAGES "images"
37 #define ELEMENT_ENTRY "entry"
38 #define ELEMENT_EXTERNALIMAGES "externalimages"
39 #define ELEMENT_EXTERNALENTRY "externalentry"
41 #define ELEMENT_NS_IMAGESCONTAINER "image:imagescontainer"
42 #define ELEMENT_NS_IMAGES "image:images"
43 #define ELEMENT_NS_ENTRY "image:entry"
44 #define ELEMENT_NS_EXTERNALIMAGES "image:externalimages"
45 #define ELEMENT_NS_EXTERNALENTRY "image:externalentry"
47 #define ATTRIBUTE_HREF "href"
48 #define ATTRIBUTE_MASKCOLOR "maskcolor"
49 #define ATTRIBUTE_COMMAND "command"
50 #define ATTRIBUTE_BITMAPINDEX "bitmap-index"
51 #define ATTRIBUTE_MASKURL "maskurl"
52 #define ATTRIBUTE_MASKMODE "maskmode"
53 #define ATTRIBUTE_HIGHCONTRASTURL "highcontrasturl"
54 #define ATTRIBUTE_HIGHCONTRASTMASKURL "highcontrastmaskurl"
55 #define ATTRIBUTE_TYPE_CDATA "CDATA"
57 #define ATTRIBUTE_MASKMODE_BITMAP "maskbitmap"
58 #define ATTRIBUTE_MASKMODE_COLOR "maskcolor"
60 #define ATTRIBUTE_XMLNS_IMAGE "xmlns:image"
61 #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink"
63 #define ATTRIBUTE_XLINK_TYPE "xlink:type"
64 #define ATTRIBUTE_XLINK_TYPE_VALUE "simple"
66 #define XMLNS_IMAGE "http://openoffice.org/2001/image"
67 #define XMLNS_XLINK "http://www.w3.org/1999/xlink"
68 #define XMLNS_IMAGE_PREFIX "image:"
69 #define XMLNS_XLINK_PREFIX "xlink:"
71 #define XMLNS_FILTER_SEPARATOR "^"
73 #define IMAGES_DOCTYPE "<!DOCTYPE image:imagecontainer PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"image.dtd\">"
75 namespace framework
78 struct ImageXMLEntryProperty
80 OReadImagesDocumentHandler::Image_XML_Namespace nNamespace;
81 char aEntryName[20];
84 ImageXMLEntryProperty ImagesEntries[OReadImagesDocumentHandler::IMG_XML_ENTRY_COUNT] =
86 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_IMAGECONTAINER },
87 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_IMAGES },
88 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_ENTRY },
89 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_EXTERNALIMAGES },
90 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_EXTERNALENTRY },
91 { OReadImagesDocumentHandler::IMG_NS_XLINK, ATTRIBUTE_HREF },
92 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKCOLOR },
93 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_COMMAND },
94 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_BITMAPINDEX },
95 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKURL },
96 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKMODE },
97 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_HIGHCONTRASTURL },
98 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_HIGHCONTRASTMASKURL }
101 OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageListsDescriptor& aItems ) :
102 m_aImageList( aItems ),
103 m_pImages( 0 ),
104 m_pExternalImages( 0 )
106 m_aImageList.pImageList = NULL;
107 m_aImageList.pExternalImageList = NULL;
109 m_nHashMaskModeBitmap = OUString( ATTRIBUTE_MASKMODE_BITMAP ).hashCode();
110 m_nHashMaskModeColor = OUString( ATTRIBUTE_MASKMODE_COLOR ).hashCode();
112 // create hash map to speed up lookup
113 for ( int i = 0; i < (int)IMG_XML_ENTRY_COUNT; i++ )
115 OUStringBuffer temp( 20 );
117 if ( ImagesEntries[i].nNamespace == IMG_NS_IMAGE )
118 temp.appendAscii( XMLNS_IMAGE );
119 else
120 temp.appendAscii( XMLNS_XLINK );
122 temp.appendAscii( XMLNS_FILTER_SEPARATOR );
123 temp.appendAscii( ImagesEntries[i].aEntryName );
124 m_aImageMap.insert( ImageHashMap::value_type( temp.makeStringAndClear(), (Image_XML_Entry)i ) );
127 // reset states
128 m_bImageContainerStartFound = false;
129 m_bImageContainerEndFound = false;
130 m_bImagesStartFound = false;
131 m_bImagesEndFound = false;
132 m_bImageStartFound = false;
133 m_bExternalImagesStartFound = false;
134 m_bExternalImagesEndFound = false;
135 m_bExternalImageStartFound = false;
138 OReadImagesDocumentHandler::~OReadImagesDocumentHandler()
142 // XDocumentHandler
143 void SAL_CALL OReadImagesDocumentHandler::startDocument()
144 throw ( SAXException, RuntimeException, std::exception )
148 void SAL_CALL OReadImagesDocumentHandler::endDocument()
149 throw( SAXException, RuntimeException, std::exception )
151 SolarMutexGuard g;
153 if (( m_bImageContainerStartFound && !m_bImageContainerEndFound ) ||
154 ( !m_bImageContainerStartFound && m_bImageContainerEndFound ) )
156 OUString aErrorMessage = getErrorLineString();
157 aErrorMessage += "No matching start or end element 'image:imagecontainer' found!";
158 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
162 void SAL_CALL OReadImagesDocumentHandler::startElement(
163 const OUString& aName, const Reference< XAttributeList > &xAttribs )
164 throw(SAXException,
165 RuntimeException,
166 std::exception)
168 SolarMutexGuard g;
170 ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName );
171 if ( pImageEntry != m_aImageMap.end() )
173 switch ( pImageEntry->second )
175 case IMG_ELEMENT_IMAGECONTAINER:
177 // image:imagecontainer element (container element for all further image elements)
178 if ( m_bImageContainerStartFound )
180 OUString aErrorMessage = getErrorLineString();
181 aErrorMessage += "Element 'image:imagecontainer' cannot be embedded into 'image:imagecontainer'!";
182 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
185 m_bImageContainerStartFound = true;
187 break;
189 case IMG_ELEMENT_IMAGES:
191 if ( !m_bImageContainerStartFound )
193 OUString aErrorMessage = getErrorLineString();
194 aErrorMessage += "Element 'image:images' must be embedded into element 'image:imagecontainer'!";
195 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
198 if ( m_bImagesStartFound )
200 OUString aErrorMessage = getErrorLineString();
201 aErrorMessage += "Element 'image:images' cannot be embedded into 'image:images'!";
202 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
205 if ( !m_aImageList.pImageList )
206 m_aImageList.pImageList = new ImageListDescriptor;
208 m_bImagesStartFound = true;
209 m_pImages = new ImageListItemDescriptor;
211 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
213 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
214 if ( pImageEntry != m_aImageMap.end() )
216 switch ( pImageEntry->second )
218 case IMG_ATTRIBUTE_HREF:
220 m_pImages->aURL = xAttribs->getValueByIndex( n );
222 break;
224 case IMG_ATTRIBUTE_MASKCOLOR:
226 OUString aColor = xAttribs->getValueByIndex( n );
228 if ( aColor.startsWith("#") )
230 // the color value is given as #rrggbb and used the hexadecimal system!!
231 sal_uInt32 nColor = aColor.copy( 1 ).toUInt32( 16 );
233 m_pImages->aMaskColor = Color( COLORDATA_RGB( nColor ) );
236 break;
238 case IMG_ATTRIBUTE_MASKURL:
240 m_pImages->aMaskURL = xAttribs->getValueByIndex( n );
242 break;
244 case IMG_ATTRIBUTE_MASKMODE:
246 sal_Int32 nHashCode = xAttribs->getValueByIndex( n ).hashCode();
247 if ( nHashCode == m_nHashMaskModeBitmap )
248 m_pImages->nMaskMode = ImageMaskMode_Bitmap;
249 else if ( nHashCode == m_nHashMaskModeColor )
250 m_pImages->nMaskMode = ImageMaskMode_Color;
251 else
253 delete m_pImages;
254 m_pImages = NULL;
256 OUString aErrorMessage = getErrorLineString();
257 aErrorMessage += "Attribute image:maskmode must be 'maskcolor' or 'maskbitmap'!";
258 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
261 break;
263 case IMG_ATTRIBUTE_HIGHCONTRASTURL:
265 m_pImages->aHighContrastURL = xAttribs->getValueByIndex( n );
267 break;
269 case IMG_ATTRIBUTE_HIGHCONTRASTMASKURL:
271 m_pImages->aHighContrastMaskURL = xAttribs->getValueByIndex( n );
273 break;
275 default:
276 break;
279 } // for
281 if ( m_pImages->aURL.isEmpty() )
283 delete m_pImages;
284 m_pImages = NULL;
286 OUString aErrorMessage = getErrorLineString();
287 aErrorMessage += "Required attribute xlink:href must have a value!";
288 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
291 break;
293 case IMG_ELEMENT_ENTRY:
295 // Check that image:entry is embedded into image:images!
296 if ( !m_bImagesStartFound )
298 delete m_pImages;
299 m_pImages = NULL;
301 OUString aErrorMessage = getErrorLineString();
302 aErrorMessage += "Element 'image:entry' must be embedded into element 'image:images'!";
303 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
306 if ( !m_pImages->pImageItemList )
307 m_pImages->pImageItemList = new ImageItemListDescriptor;
309 m_bImageStartFound = true;
311 // Create new image item descriptor
312 ImageItemDescriptor* pItem = new ImageItemDescriptor;
313 pItem->nIndex = -1;
315 // Read attributes for this image definition
316 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
318 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
319 if ( pImageEntry != m_aImageMap.end() )
321 switch ( pImageEntry->second )
323 case IMG_ATTRIBUTE_COMMAND:
325 pItem->aCommandURL = xAttribs->getValueByIndex( n );
327 break;
329 case IMG_ATTRIBUTE_BITMAPINDEX:
331 pItem->nIndex = xAttribs->getValueByIndex( n ).toInt32();
333 break;
335 default:
336 break;
341 // Check required attribute "bitmap-index"
342 if ( pItem->nIndex < 0 )
344 delete pItem;
345 delete m_pImages;
346 m_pImages = NULL;
348 OUString aErrorMessage = getErrorLineString();
349 aErrorMessage += "Required attribute 'image:bitmap-index' must have a value >= 0!";
350 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
353 // Check required attribute "command"
354 if ( pItem->aCommandURL.isEmpty() )
356 delete pItem;
357 delete m_pImages;
358 m_pImages = NULL;
360 OUString aErrorMessage = getErrorLineString();
361 aErrorMessage += "Required attribute 'image:command' must have a value!";
362 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
365 m_pImages->pImageItemList->push_back( pItem );
367 break;
369 case IMG_ELEMENT_EXTERNALIMAGES:
371 // Check that image:externalimages is embedded into image:imagecontainer
372 if ( !m_bImageContainerStartFound )
374 delete m_pImages;
375 m_pImages = NULL;
377 OUString aErrorMessage = getErrorLineString();
378 aErrorMessage += "Element 'image:externalimages' must be embedded into element 'image:imagecontainer'!";
379 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
382 // Check that image:externalentry is NOT embedded into image:externalentry
383 if ( m_bExternalImagesStartFound )
385 delete m_pImages;
386 m_pImages = NULL;
388 OUString aErrorMessage = getErrorLineString();
389 aErrorMessage += "Element 'image:externalimages' cannot be embedded into 'image:externalimages'!";
390 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
393 // Create unique external image container
394 m_bExternalImagesStartFound = true;
395 m_pExternalImages = new ExternalImageItemListDescriptor;
397 break;
399 case IMG_ELEMENT_EXTERNALENTRY:
401 if ( !m_bExternalImagesStartFound )
403 delete m_pImages;
404 delete m_pExternalImages;
405 m_pImages = NULL;
406 m_pExternalImages = NULL;
408 OUString aErrorMessage = getErrorLineString();
409 aErrorMessage += "Element 'image:externalentry' must be embedded into 'image:externalimages'!";
410 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
413 if ( m_bExternalImageStartFound )
415 delete m_pImages;
416 delete m_pExternalImages;
417 m_pImages = NULL;
418 m_pExternalImages = NULL;
420 OUString aErrorMessage = getErrorLineString();
421 aErrorMessage += "Element 'image:externalentry' cannot be embedded into 'image:externalentry'!";
422 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
425 m_bExternalImageStartFound = true;
427 ExternalImageItemDescriptor* pItem = new ExternalImageItemDescriptor;
429 // Read attributes for this external image definition
430 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
432 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
433 if ( pImageEntry != m_aImageMap.end() )
435 switch ( pImageEntry->second )
437 case IMG_ATTRIBUTE_COMMAND:
439 pItem->aCommandURL = xAttribs->getValueByIndex( n );
441 break;
443 case IMG_ATTRIBUTE_HREF:
445 pItem->aURL = xAttribs->getValueByIndex( n );
447 break;
449 default:
450 break;
455 // Check required attribute "command"
456 if ( pItem->aCommandURL.isEmpty() )
458 delete pItem;
459 delete m_pImages;
460 delete m_pExternalImages;
461 m_pImages = NULL;
462 m_pExternalImages = NULL;
464 OUString aErrorMessage = getErrorLineString();
465 aErrorMessage += "Required attribute 'image:command' must have a value!";
466 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
469 // Check required attribute "href"
470 if ( pItem->aURL.isEmpty() )
472 delete pItem;
473 delete m_pImages;
474 delete m_pExternalImages;
475 m_pImages = NULL;
476 m_pExternalImages = NULL;
478 OUString aErrorMessage = getErrorLineString();
479 aErrorMessage += "Required attribute 'xlink:href' must have a value!";
480 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
483 if ( m_pExternalImages )
484 m_pExternalImages->push_back( pItem );
485 else
486 delete pItem;
488 break;
490 default:
491 break;
496 void SAL_CALL OReadImagesDocumentHandler::endElement(const OUString& aName)
497 throw(SAXException,
498 RuntimeException,
499 std::exception)
501 SolarMutexGuard g;
503 ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName );
504 if ( pImageEntry != m_aImageMap.end() )
506 switch ( pImageEntry->second )
508 case IMG_ELEMENT_IMAGECONTAINER:
510 m_bImageContainerEndFound = true;
512 break;
514 case IMG_ELEMENT_IMAGES:
516 if ( m_pImages )
518 if ( m_aImageList.pImageList )
519 m_aImageList.pImageList->push_back( m_pImages );
520 m_pImages = NULL;
522 m_bImagesStartFound = false;
524 break;
526 case IMG_ELEMENT_ENTRY:
528 m_bImageStartFound = false;
530 break;
532 case IMG_ELEMENT_EXTERNALIMAGES:
534 if ( m_pExternalImages && !m_aImageList.pExternalImageList )
536 if ( !m_aImageList.pExternalImageList )
537 m_aImageList.pExternalImageList = m_pExternalImages;
540 m_bExternalImagesStartFound = false;
541 m_pExternalImages = NULL;
543 break;
545 case IMG_ELEMENT_EXTERNALENTRY:
547 m_bExternalImageStartFound = false;
549 break;
551 default:
552 break;
557 void SAL_CALL OReadImagesDocumentHandler::characters(const OUString&)
558 throw( SAXException, RuntimeException, std::exception )
562 void SAL_CALL OReadImagesDocumentHandler::ignorableWhitespace(const OUString&)
563 throw( SAXException, RuntimeException, std::exception )
567 void SAL_CALL OReadImagesDocumentHandler::processingInstruction(
568 const OUString& /*aTarget*/, const OUString& /*aData*/ )
569 throw( SAXException, RuntimeException, std::exception )
573 void SAL_CALL OReadImagesDocumentHandler::setDocumentLocator(
574 const Reference< XLocator > &xLocator)
575 throw( SAXException, RuntimeException, std::exception )
577 SolarMutexGuard g;
578 m_xLocator = xLocator;
581 OUString OReadImagesDocumentHandler::getErrorLineString()
583 SolarMutexGuard g;
584 if ( m_xLocator.is() )
586 OUStringBuffer buffer("Line: ");
587 buffer.append(m_xLocator->getLineNumber());
588 buffer.append(" - ");
589 return buffer.makeStringAndClear();
591 else
592 return OUString();
595 // OWriteImagesDocumentHandler
597 OWriteImagesDocumentHandler::OWriteImagesDocumentHandler(
598 const ImageListsDescriptor& aItems,
599 Reference< XDocumentHandler > rWriteDocumentHandler ) :
600 m_aImageListsItems( aItems ),
601 m_xWriteDocumentHandler( rWriteDocumentHandler )
603 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
604 m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
605 m_aAttributeType = ATTRIBUTE_TYPE_CDATA;
606 m_aXMLImageNS = XMLNS_IMAGE_PREFIX;
607 m_aXMLXlinkNS = XMLNS_XLINK_PREFIX;
608 m_aAttributeXlinkType = ATTRIBUTE_XLINK_TYPE;
609 m_aAttributeValueSimple = ATTRIBUTE_XLINK_TYPE_VALUE;
612 OWriteImagesDocumentHandler::~OWriteImagesDocumentHandler()
616 void OWriteImagesDocumentHandler::WriteImagesDocument() throw
617 ( SAXException, RuntimeException )
619 SolarMutexGuard g;
621 m_xWriteDocumentHandler->startDocument();
623 // write DOCTYPE line!
624 Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
625 if ( xExtendedDocHandler.is() )
627 xExtendedDocHandler->unknown( OUString( IMAGES_DOCTYPE ) );
628 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
631 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
632 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
634 pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_IMAGE),
635 m_aAttributeType,
636 OUString( XMLNS_IMAGE ) );
638 pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_XLINK ),
639 m_aAttributeType,
640 OUString( XMLNS_XLINK ) );
642 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGESCONTAINER ), pList );
643 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
645 if ( m_aImageListsItems.pImageList )
647 ImageListDescriptor* pImageList = m_aImageListsItems.pImageList;
649 for ( sal_uInt16 i = 0; i < m_aImageListsItems.pImageList->size(); i++ )
651 const ImageListItemDescriptor* pImageItems = &(*pImageList)[i];
652 WriteImageList( pImageItems );
656 if ( m_aImageListsItems.pExternalImageList )
658 WriteExternalImageList( m_aImageListsItems.pExternalImageList );
661 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
662 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGESCONTAINER ) );
663 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
664 m_xWriteDocumentHandler->endDocument();
667 // protected member functions
669 void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* pImageList ) throw
670 ( SAXException, RuntimeException )
672 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
673 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
675 // save required attributes
676 pList->AddAttribute( m_aAttributeXlinkType,
677 m_aAttributeType,
678 m_aAttributeValueSimple );
680 pList->AddAttribute( m_aXMLXlinkNS + ATTRIBUTE_HREF,
681 m_aAttributeType,
682 pImageList->aURL );
684 if ( pImageList->nMaskMode == ImageMaskMode_Bitmap )
686 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKMODE,
687 m_aAttributeType,
688 OUString( ATTRIBUTE_MASKMODE_BITMAP ) );
690 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKURL,
691 m_aAttributeType,
692 pImageList->aMaskURL );
694 if ( !pImageList->aHighContrastMaskURL.isEmpty() )
696 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_HIGHCONTRASTMASKURL,
697 m_aAttributeType,
698 pImageList->aHighContrastMaskURL );
701 else
703 OUStringBuffer aColorStrBuffer( 8 );
704 sal_Int64 nValue = pImageList->aMaskColor.GetRGBColor();
706 aColorStrBuffer.appendAscii( "#" );
707 aColorStrBuffer.append( OUString::number( nValue, 16 ));
709 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKCOLOR,
710 m_aAttributeType,
711 aColorStrBuffer.makeStringAndClear() );
713 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKMODE,
714 m_aAttributeType,
715 OUString( ATTRIBUTE_MASKMODE_COLOR ) );
718 if ( !pImageList->aHighContrastURL.isEmpty() )
720 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_HIGHCONTRASTURL,
721 m_aAttributeType,
722 pImageList->aHighContrastURL );
725 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGES ), xList );
726 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
728 ImageItemListDescriptor* pImageItemList = pImageList->pImageItemList;
729 if ( pImageItemList )
731 for ( sal_uInt16 i = 0; i < pImageItemList->size(); i++ )
732 WriteImage( &(*pImageItemList)[i] );
735 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGES ) );
736 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
739 void OWriteImagesDocumentHandler::WriteImage( const ImageItemDescriptor* pImage ) throw
740 ( SAXException, RuntimeException )
742 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
743 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
745 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_BITMAPINDEX,
746 m_aAttributeType,
747 OUString::number( pImage->nIndex ) );
749 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_COMMAND,
750 m_aAttributeType,
751 pImage->aCommandURL );
753 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_ENTRY ), xList );
754 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
756 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_ENTRY ) );
757 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
760 void OWriteImagesDocumentHandler::WriteExternalImageList( const ExternalImageItemListDescriptor* pExternalImageList ) throw
761 ( SAXException, RuntimeException )
763 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALIMAGES ), m_xEmptyList );
764 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
766 for ( sal_uInt16 i = 0; i < pExternalImageList->size(); i++ )
768 const ExternalImageItemDescriptor* pItem = &(*pExternalImageList)[i];
769 WriteExternalImage( pItem );
772 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
773 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALIMAGES ) );
774 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
777 void OWriteImagesDocumentHandler::WriteExternalImage( const ExternalImageItemDescriptor* pExternalImage ) throw
778 ( SAXException, RuntimeException )
780 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
781 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
783 // save required attributes
784 pList->AddAttribute( m_aAttributeXlinkType,
785 m_aAttributeType,
786 m_aAttributeValueSimple );
788 if ( !pExternalImage->aURL.isEmpty() )
790 pList->AddAttribute( m_aXMLXlinkNS + ATTRIBUTE_HREF,
791 m_aAttributeType,
792 pExternalImage->aURL );
795 if ( !pExternalImage->aCommandURL.isEmpty() )
797 pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_COMMAND,
798 m_aAttributeType,
799 pExternalImage->aCommandURL );
802 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALENTRY ), xList );
803 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
805 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALENTRY ) );
806 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
809 } // namespace framework
811 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */