bump product version to 4.1.6.2
[LibreOffice.git] / framework / source / xml / imagesdocumenthandler.cxx
blob5821266c4fbe8c455d36dc8ceecc05836ab8ef0d
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 .
21 #include <stdio.h>
23 #include <threadhelp/resetableguard.hxx>
24 #include <xml/imagesdocumenthandler.hxx>
25 #include <macros/debug.hxx>
27 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
29 #include <vcl/svapp.hxx>
30 #include <vcl/toolbox.hxx>
31 #include <rtl/ustrbuf.hxx>
33 #include <comphelper/attributelist.hxx>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
38 #define ELEMENT_IMAGECONTAINER "imagescontainer"
39 #define ELEMENT_IMAGES "images"
40 #define ELEMENT_ENTRY "entry"
41 #define ELEMENT_EXTERNALIMAGES "externalimages"
42 #define ELEMENT_EXTERNALENTRY "externalentry"
44 #define ELEMENT_NS_IMAGESCONTAINER "image:imagescontainer"
45 #define ELEMENT_NS_IMAGES "image:images"
46 #define ELEMENT_NS_ENTRY "image:entry"
47 #define ELEMENT_NS_EXTERNALIMAGES "image:externalimages"
48 #define ELEMENT_NS_EXTERNALENTRY "image:externalentry"
50 #define ATTRIBUTE_HREF "href"
51 #define ATTRIBUTE_MASKCOLOR "maskcolor"
52 #define ATTRIBUTE_COMMAND "command"
53 #define ATTRIBUTE_BITMAPINDEX "bitmap-index"
54 #define ATTRIBUTE_MASKURL "maskurl"
55 #define ATTRIBUTE_MASKMODE "maskmode"
56 #define ATTRIBUTE_HIGHCONTRASTURL "highcontrasturl"
57 #define ATTRIBUTE_HIGHCONTRASTMASKURL "highcontrastmaskurl"
58 #define ATTRIBUTE_TYPE_CDATA "CDATA"
60 #define ATTRIBUTE_MASKMODE_BITMAP "maskbitmap"
61 #define ATTRIBUTE_MASKMODE_COLOR "maskcolor"
63 #define ATTRIBUTE_XMLNS_IMAGE "xmlns:image"
64 #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink"
66 #define ATTRIBUTE_XLINK_TYPE "xlink:type"
67 #define ATTRIBUTE_XLINK_TYPE_VALUE "simple"
69 #define XMLNS_IMAGE "http://openoffice.org/2001/image"
70 #define XMLNS_XLINK "http://www.w3.org/1999/xlink"
71 #define XMLNS_IMAGE_PREFIX "image:"
72 #define XMLNS_XLINK_PREFIX "xlink:"
74 #define XMLNS_FILTER_SEPARATOR "^"
76 #define IMAGES_DOCTYPE "<!DOCTYPE image:imagecontainer PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"image.dtd\">"
78 namespace framework
81 struct ImageXMLEntryProperty
83 OReadImagesDocumentHandler::Image_XML_Namespace nNamespace;
84 char aEntryName[20];
87 ImageXMLEntryProperty ImagesEntries[OReadImagesDocumentHandler::IMG_XML_ENTRY_COUNT] =
89 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_IMAGECONTAINER },
90 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_IMAGES },
91 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_ENTRY },
92 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_EXTERNALIMAGES },
93 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ELEMENT_EXTERNALENTRY },
94 { OReadImagesDocumentHandler::IMG_NS_XLINK, ATTRIBUTE_HREF },
95 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKCOLOR },
96 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_COMMAND },
97 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_BITMAPINDEX },
98 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKURL },
99 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_MASKMODE },
100 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_HIGHCONTRASTURL },
101 { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_HIGHCONTRASTMASKURL }
105 OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageListsDescriptor& aItems ) :
106 ThreadHelpBase( &Application::GetSolarMutex() ),
107 m_aImageList( aItems ),
108 m_pImages( 0 ),
109 m_pExternalImages( 0 )
111 m_aImageList.pImageList = NULL;
112 m_aImageList.pExternalImageList = NULL;
114 m_nHashMaskModeBitmap = OUString( ATTRIBUTE_MASKMODE_BITMAP ).hashCode();
115 m_nHashMaskModeColor = OUString( ATTRIBUTE_MASKMODE_COLOR ).hashCode();
117 // create hash map to speed up lookup
118 for ( int i = 0; i < (int)IMG_XML_ENTRY_COUNT; i++ )
120 OUStringBuffer temp( 20 );
122 if ( ImagesEntries[i].nNamespace == IMG_NS_IMAGE )
123 temp.appendAscii( XMLNS_IMAGE );
124 else
125 temp.appendAscii( XMLNS_XLINK );
127 temp.appendAscii( XMLNS_FILTER_SEPARATOR );
128 temp.appendAscii( ImagesEntries[i].aEntryName );
129 m_aImageMap.insert( ImageHashMap::value_type( temp.makeStringAndClear(), (Image_XML_Entry)i ) );
132 // reset states
133 m_bImageContainerStartFound = sal_False;
134 m_bImageContainerEndFound = sal_False;
135 m_bImagesStartFound = sal_False;
136 m_bImagesEndFound = sal_False;
137 m_bImageStartFound = sal_False;
138 m_bExternalImagesStartFound = sal_False;
139 m_bExternalImagesEndFound = sal_False;
140 m_bExternalImageStartFound = sal_False;
143 OReadImagesDocumentHandler::~OReadImagesDocumentHandler()
147 // XDocumentHandler
148 void SAL_CALL OReadImagesDocumentHandler::startDocument(void)
149 throw ( SAXException, RuntimeException )
153 void SAL_CALL OReadImagesDocumentHandler::endDocument(void)
154 throw( SAXException, RuntimeException )
156 ResetableGuard aGuard( m_aLock );
158 if (( m_bImageContainerStartFound && !m_bImageContainerEndFound ) ||
159 ( !m_bImageContainerStartFound && m_bImageContainerEndFound ) )
161 OUString aErrorMessage = getErrorLineString();
162 aErrorMessage += "No matching start or end element 'image:imagecontainer' found!";
163 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
167 void SAL_CALL OReadImagesDocumentHandler::startElement(
168 const OUString& aName, const Reference< XAttributeList > &xAttribs )
169 throw( SAXException, RuntimeException )
171 ResetableGuard aGuard( m_aLock );
173 ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName ) ;
174 if ( pImageEntry != m_aImageMap.end() )
176 switch ( pImageEntry->second )
178 case IMG_ELEMENT_IMAGECONTAINER:
180 // image:imagecontainer element (container element for all further image elements)
181 if ( m_bImageContainerStartFound )
183 OUString aErrorMessage = getErrorLineString();
184 aErrorMessage += "Element 'image:imagecontainer' cannot be embeded into 'image:imagecontainer'!";
185 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
188 m_bImageContainerStartFound = sal_True;
190 break;
192 case IMG_ELEMENT_IMAGES:
194 if ( !m_bImageContainerStartFound )
196 OUString aErrorMessage = getErrorLineString();
197 aErrorMessage += "Element 'image:images' must be embeded into element 'image:imagecontainer'!";
198 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
201 if ( m_bImagesStartFound )
203 OUString aErrorMessage = getErrorLineString();
204 aErrorMessage += "Element 'image:images' cannot be embeded into 'image:images'!";
205 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
208 if ( !m_aImageList.pImageList )
209 m_aImageList.pImageList = new ImageListDescriptor;
211 m_bImagesStartFound = sal_True;
212 m_pImages = new ImageListItemDescriptor;
214 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
216 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
217 if ( pImageEntry != m_aImageMap.end() )
219 switch ( pImageEntry->second )
221 case IMG_ATTRIBUTE_HREF:
223 m_pImages->aURL = xAttribs->getValueByIndex( n );
225 break;
227 case IMG_ATTRIBUTE_MASKCOLOR:
229 OUString aColor = xAttribs->getValueByIndex( n );
231 if ( !aColor.isEmpty() )
233 if ( aColor.getStr()[0] == '#' )
235 // the color value is given as #rrggbb and used the hexadecimal system!!
236 sal_uInt32 nColor = aColor.copy( 1 ).toInt32( 16 );
238 m_pImages->aMaskColor = Color( COLORDATA_RGB( nColor ) );
242 break;
244 case IMG_ATTRIBUTE_MASKURL:
246 m_pImages->aMaskURL = xAttribs->getValueByIndex( n );
248 break;
250 case IMG_ATTRIBUTE_MASKMODE:
252 sal_Int32 nHashCode = xAttribs->getValueByIndex( n ).hashCode();
253 if ( nHashCode == m_nHashMaskModeBitmap )
254 m_pImages->nMaskMode = ImageMaskMode_Bitmap;
255 else if ( nHashCode == m_nHashMaskModeColor )
256 m_pImages->nMaskMode = ImageMaskMode_Color;
257 else
259 delete m_pImages;
260 m_pImages = NULL;
262 OUString aErrorMessage = getErrorLineString();
263 aErrorMessage += "Attribute image:maskmode must be 'maskcolor' or 'maskbitmap'!";
264 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
267 break;
269 case IMG_ATTRIBUTE_HIGHCONTRASTURL:
271 m_pImages->aHighContrastURL = xAttribs->getValueByIndex( n );
273 break;
275 case IMG_ATTRIBUTE_HIGHCONTRASTMASKURL:
277 m_pImages->aHighContrastMaskURL = xAttribs->getValueByIndex( n );
279 break;
281 default:
282 break;
285 } // for
287 if ( m_pImages->aURL.Len() == 0 )
289 delete m_pImages;
290 m_pImages = NULL;
292 OUString aErrorMessage = getErrorLineString();
293 aErrorMessage += "Required attribute xlink:href must have a value!";
294 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
297 break;
299 case IMG_ELEMENT_ENTRY:
301 // Check that image:entry is embeded into image:images!
302 if ( !m_bImagesStartFound )
304 delete m_pImages;
305 m_pImages = NULL;
307 OUString aErrorMessage = getErrorLineString();
308 aErrorMessage += "Element 'image:entry' must be embeded into element 'image:images'!";
309 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
312 if ( !m_pImages->pImageItemList )
313 m_pImages->pImageItemList = new ImageItemListDescriptor;
315 m_bImageStartFound = sal_True;
317 // Create new image item descriptor
318 ImageItemDescriptor* pItem = new ImageItemDescriptor;
319 pItem->nIndex = -1;
321 // Read attributes for this image definition
322 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
324 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
325 if ( pImageEntry != m_aImageMap.end() )
327 switch ( pImageEntry->second )
329 case IMG_ATTRIBUTE_COMMAND:
331 pItem->aCommandURL = xAttribs->getValueByIndex( n );
333 break;
335 case IMG_ATTRIBUTE_BITMAPINDEX:
337 pItem->nIndex = xAttribs->getValueByIndex( n ).toInt32();
339 break;
341 default:
342 break;
347 // Check required attribute "bitmap-index"
348 if ( pItem->nIndex < 0 )
350 delete pItem;
351 delete m_pImages;
352 m_pImages = NULL;
354 OUString aErrorMessage = getErrorLineString();
355 aErrorMessage += "Required attribute 'image:bitmap-index' must have a value >= 0!";
356 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
359 // Check required attribute "command"
360 if ( pItem->aCommandURL.Len() == 0 )
362 delete pItem;
363 delete m_pImages;
364 m_pImages = NULL;
366 OUString aErrorMessage = getErrorLineString();
367 aErrorMessage += "Required attribute 'image:command' must have a value!";
368 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
371 if ( m_pImages )
372 m_pImages->pImageItemList->push_back( pItem );
374 break;
376 case IMG_ELEMENT_EXTERNALIMAGES:
378 // Check that image:externalimages is embeded into image:imagecontainer
379 if ( !m_bImageContainerStartFound )
381 delete m_pImages;
382 m_pImages = NULL;
384 OUString aErrorMessage = getErrorLineString();
385 aErrorMessage += "Element 'image:externalimages' must be embeded into element 'image:imagecontainer'!";
386 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
389 // Check that image:externalentry is NOT embeded into image:externalentry
390 if ( m_bExternalImagesStartFound )
392 delete m_pImages;
393 m_pImages = NULL;
395 OUString aErrorMessage = getErrorLineString();
396 aErrorMessage += "Element 'image:externalimages' cannot be embeded into 'image:externalimages'!";
397 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
400 // Create unique external image container
401 m_bExternalImagesStartFound = sal_True;
402 m_pExternalImages = new ExternalImageItemListDescriptor;
404 break;
406 case IMG_ELEMENT_EXTERNALENTRY:
408 if ( !m_bExternalImagesStartFound )
410 delete m_pImages;
411 delete m_pExternalImages;
412 m_pImages = NULL;
413 m_pExternalImages = NULL;
415 OUString aErrorMessage = getErrorLineString();
416 aErrorMessage += "Element 'image:externalentry' must be embeded into 'image:externalimages'!";
417 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
420 if ( m_bExternalImageStartFound )
422 delete m_pImages;
423 delete m_pExternalImages;
424 m_pImages = NULL;
425 m_pExternalImages = NULL;
427 OUString aErrorMessage = getErrorLineString();
428 aErrorMessage += "Element 'image:externalentry' cannot be embeded into 'image:externalentry'!";
429 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
432 m_bExternalImageStartFound = sal_True;
434 ExternalImageItemDescriptor* pItem = new ExternalImageItemDescriptor;
436 // Read attributes for this external image definition
437 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
439 pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
440 if ( pImageEntry != m_aImageMap.end() )
442 switch ( pImageEntry->second )
444 case IMG_ATTRIBUTE_COMMAND:
446 pItem->aCommandURL = xAttribs->getValueByIndex( n );
448 break;
450 case IMG_ATTRIBUTE_HREF:
452 pItem->aURL = xAttribs->getValueByIndex( n );
454 break;
456 default:
457 break;
462 // Check required attribute "command"
463 if ( pItem->aCommandURL.Len() == 0 )
465 delete pItem;
466 delete m_pImages;
467 delete m_pExternalImages;
468 m_pImages = NULL;
469 m_pExternalImages = NULL;
471 OUString aErrorMessage = getErrorLineString();
472 aErrorMessage += "Required attribute 'image:command' must have a value!";
473 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
476 // Check required attribute "href"
477 if ( pItem->aURL.Len() == 0 )
479 delete pItem;
480 delete m_pImages;
481 delete m_pExternalImages;
482 m_pImages = NULL;
483 m_pExternalImages = NULL;
485 OUString aErrorMessage = getErrorLineString();
486 aErrorMessage += "Required attribute 'xlink:href' must have a value!";
487 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
490 if ( m_pExternalImages )
491 m_pExternalImages->push_back( pItem );
492 else
493 delete pItem;
495 break;
497 default:
498 break;
503 void SAL_CALL OReadImagesDocumentHandler::endElement(const OUString& aName)
504 throw( SAXException, RuntimeException )
506 ResetableGuard aGuard( m_aLock );
508 ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName ) ;
509 if ( pImageEntry != m_aImageMap.end() )
511 switch ( pImageEntry->second )
513 case IMG_ELEMENT_IMAGECONTAINER:
515 m_bImageContainerEndFound = sal_True;
517 break;
519 case IMG_ELEMENT_IMAGES:
521 if ( m_pImages )
523 if ( m_aImageList.pImageList )
524 m_aImageList.pImageList->push_back( m_pImages );
525 m_pImages = NULL;
527 m_bImagesStartFound = sal_False;
529 break;
531 case IMG_ELEMENT_ENTRY:
533 m_bImageStartFound = sal_False;
535 break;
537 case IMG_ELEMENT_EXTERNALIMAGES:
539 if ( m_pExternalImages && !m_aImageList.pExternalImageList )
541 if ( !m_aImageList.pExternalImageList )
542 m_aImageList.pExternalImageList = m_pExternalImages;
545 m_bExternalImagesStartFound = sal_False;
546 m_pExternalImages = NULL;
548 break;
550 case IMG_ELEMENT_EXTERNALENTRY:
552 m_bExternalImageStartFound = sal_False;
554 break;
556 default:
557 break;
562 void SAL_CALL OReadImagesDocumentHandler::characters(const OUString&)
563 throw( SAXException, RuntimeException )
567 void SAL_CALL OReadImagesDocumentHandler::ignorableWhitespace(const OUString&)
568 throw( SAXException, RuntimeException )
572 void SAL_CALL OReadImagesDocumentHandler::processingInstruction(
573 const OUString& /*aTarget*/, const OUString& /*aData*/ )
574 throw( SAXException, RuntimeException )
578 void SAL_CALL OReadImagesDocumentHandler::setDocumentLocator(
579 const Reference< XLocator > &xLocator)
580 throw( SAXException, RuntimeException )
582 ResetableGuard aGuard( m_aLock );
584 m_xLocator = xLocator;
587 OUString OReadImagesDocumentHandler::getErrorLineString()
589 ResetableGuard aGuard( m_aLock );
591 char buffer[32];
593 if ( m_xLocator.is() )
595 snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() ));
596 return OUString::createFromAscii( buffer );
598 else
599 return OUString();
603 //_________________________________________________________________________________________________________________
604 // OWriteImagesDocumentHandler
605 //_________________________________________________________________________________________________________________
607 OWriteImagesDocumentHandler::OWriteImagesDocumentHandler(
608 const ImageListsDescriptor& aItems,
609 Reference< XDocumentHandler > rWriteDocumentHandler ) :
610 ThreadHelpBase( &Application::GetSolarMutex() ),
611 m_aImageListsItems( aItems ),
612 m_xWriteDocumentHandler( rWriteDocumentHandler )
614 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
615 m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
616 m_aAttributeType = OUString( ATTRIBUTE_TYPE_CDATA );
617 m_aXMLImageNS = OUString( XMLNS_IMAGE_PREFIX );
618 m_aXMLXlinkNS = OUString( XMLNS_XLINK_PREFIX );
619 m_aAttributeXlinkType = OUString( ATTRIBUTE_XLINK_TYPE );
620 m_aAttributeValueSimple = OUString( ATTRIBUTE_XLINK_TYPE_VALUE );
623 OWriteImagesDocumentHandler::~OWriteImagesDocumentHandler()
627 void OWriteImagesDocumentHandler::WriteImagesDocument() throw
628 ( SAXException, RuntimeException )
630 ResetableGuard aGuard( m_aLock );
632 m_xWriteDocumentHandler->startDocument();
634 // write DOCTYPE line!
635 Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
636 if ( xExtendedDocHandler.is() )
638 xExtendedDocHandler->unknown( OUString( IMAGES_DOCTYPE ) );
639 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
642 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
643 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
645 pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_IMAGE),
646 m_aAttributeType,
647 OUString( XMLNS_IMAGE ) );
649 pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_XLINK ),
650 m_aAttributeType,
651 OUString( XMLNS_XLINK ) );
653 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGESCONTAINER ), pList );
654 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
656 if ( m_aImageListsItems.pImageList )
658 ImageListDescriptor* pImageList = m_aImageListsItems.pImageList;
660 for ( sal_uInt16 i = 0; i < m_aImageListsItems.pImageList->size(); i++ )
662 const ImageListItemDescriptor* pImageItems = &(*pImageList)[i];
663 WriteImageList( pImageItems );
667 if ( m_aImageListsItems.pExternalImageList )
669 WriteExternalImageList( m_aImageListsItems.pExternalImageList );
672 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
673 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGESCONTAINER ) );
674 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
675 m_xWriteDocumentHandler->endDocument();
678 //_________________________________________________________________________________________________________________
679 // protected member functions
680 //_________________________________________________________________________________________________________________
682 void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* pImageList ) throw
683 ( SAXException, RuntimeException )
685 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
686 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
688 // save required attributes
689 pList->AddAttribute( m_aAttributeXlinkType,
690 m_aAttributeType,
691 m_aAttributeValueSimple );
693 pList->AddAttribute( m_aXMLXlinkNS + OUString( ATTRIBUTE_HREF ),
694 m_aAttributeType,
695 pImageList->aURL );
697 if ( pImageList->nMaskMode == ImageMaskMode_Bitmap )
699 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKMODE ),
700 m_aAttributeType,
701 OUString( ATTRIBUTE_MASKMODE_BITMAP ) );
703 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKURL ),
704 m_aAttributeType,
705 pImageList->aMaskURL );
707 if ( pImageList->aHighContrastMaskURL.Len() > 0 )
709 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_HIGHCONTRASTMASKURL ),
710 m_aAttributeType,
711 pImageList->aHighContrastMaskURL );
714 else
716 OUStringBuffer aColorStrBuffer( 8 );
717 sal_Int64 nValue = pImageList->aMaskColor.GetRGBColor();
719 aColorStrBuffer.appendAscii( "#" );
720 aColorStrBuffer.append( OUString::valueOf( nValue, 16 ));
722 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKCOLOR ),
723 m_aAttributeType,
724 aColorStrBuffer.makeStringAndClear() );
726 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKMODE ),
727 m_aAttributeType,
728 OUString( ATTRIBUTE_MASKMODE_COLOR ) );
731 if ( pImageList->aHighContrastURL.Len() > 0 )
733 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_HIGHCONTRASTURL ),
734 m_aAttributeType,
735 pImageList->aHighContrastURL );
738 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGES ), xList );
739 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
741 ImageItemListDescriptor* pImageItemList = pImageList->pImageItemList;
742 if ( pImageItemList )
744 for ( sal_uInt16 i = 0; i < pImageItemList->size(); i++ )
745 WriteImage( &(*pImageItemList)[i] );
748 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGES ) );
749 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
752 void OWriteImagesDocumentHandler::WriteImage( const ImageItemDescriptor* pImage ) throw
753 ( SAXException, RuntimeException )
755 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
756 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
758 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_BITMAPINDEX ),
759 m_aAttributeType,
760 OUString::valueOf( (sal_Int32)pImage->nIndex ) );
762 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_COMMAND ),
763 m_aAttributeType,
764 pImage->aCommandURL );
766 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_ENTRY ), xList );
767 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
769 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_ENTRY ) );
770 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
773 void OWriteImagesDocumentHandler::WriteExternalImageList( const ExternalImageItemListDescriptor* pExternalImageList ) throw
774 ( SAXException, RuntimeException )
776 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALIMAGES ), m_xEmptyList );
777 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
779 for ( sal_uInt16 i = 0; i < pExternalImageList->size(); i++ )
781 const ExternalImageItemDescriptor* pItem = &(*pExternalImageList)[i];
782 WriteExternalImage( pItem );
785 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
786 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALIMAGES ) );
787 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
790 void OWriteImagesDocumentHandler::WriteExternalImage( const ExternalImageItemDescriptor* pExternalImage ) throw
791 ( SAXException, RuntimeException )
793 ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
794 Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
796 // save required attributes
797 pList->AddAttribute( m_aAttributeXlinkType,
798 m_aAttributeType,
799 m_aAttributeValueSimple );
801 if ( pExternalImage->aURL.Len() > 0 )
803 pList->AddAttribute( m_aXMLXlinkNS + OUString( ATTRIBUTE_HREF ),
804 m_aAttributeType,
805 pExternalImage->aURL );
808 if ( pExternalImage->aCommandURL.Len() > 0 )
810 pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_COMMAND ),
811 m_aAttributeType,
812 pExternalImage->aCommandURL );
815 m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALENTRY ), xList );
816 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
818 m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALENTRY ) );
819 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
822 } // namespace framework
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */