1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imagesdocumenthandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 #include <threadhelp/resetableguard.hxx>
41 #include <xml/imagesdocumenthandler.hxx>
42 #include <macros/debug.hxx>
44 //_________________________________________________________________________________________________________________
46 //_________________________________________________________________________________________________________________
48 #ifndef __COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_
49 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
52 //_________________________________________________________________________________________________________________
54 //_________________________________________________________________________________________________________________
55 #include <vcl/svapp.hxx>
56 #include <vcl/toolbox.hxx>
57 #include <rtl/ustrbuf.hxx>
59 #include <comphelper/attributelist.hxx>
61 //_________________________________________________________________________________________________________________
63 //_________________________________________________________________________________________________________________
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::xml::sax
;
68 #define ELEMENT_IMAGECONTAINER "imagescontainer"
69 #define ELEMENT_IMAGES "images"
70 #define ELEMENT_ENTRY "entry"
71 #define ELEMENT_EXTERNALIMAGES "externalimages"
72 #define ELEMENT_EXTERNALENTRY "externalentry"
74 #define ELEMENT_NS_IMAGESCONTAINER "image:imagescontainer"
75 #define ELEMENT_NS_IMAGES "image:images"
76 #define ELEMENT_NS_ENTRY "image:entry"
77 #define ELEMENT_NS_EXTERNALIMAGES "image:externalimages"
78 #define ELEMENT_NS_EXTERNALENTRY "image:externalentry"
80 #define ATTRIBUTE_HREF "href"
81 #define ATTRIBUTE_MASKCOLOR "maskcolor"
82 #define ATTRIBUTE_COMMAND "command"
83 #define ATTRIBUTE_BITMAPINDEX "bitmap-index"
84 #define ATTRIBUTE_MASKURL "maskurl"
85 #define ATTRIBUTE_MASKMODE "maskmode"
86 #define ATTRIBUTE_HIGHCONTRASTURL "highcontrasturl"
87 #define ATTRIBUTE_HIGHCONTRASTMASKURL "highcontrastmaskurl"
88 #define ATTRIBUTE_TYPE_CDATA "CDATA"
90 #define ATTRIBUTE_MASKMODE_BITMAP "maskbitmap"
91 #define ATTRIBUTE_MASKMODE_COLOR "maskcolor"
93 #define ATTRIBUTE_XMLNS_IMAGE "xmlns:image"
94 #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink"
96 #define ATTRIBUTE_XLINK_TYPE "xlink:type"
97 #define ATTRIBUTE_XLINK_TYPE_VALUE "simple"
99 #define XMLNS_IMAGE "http://openoffice.org/2001/image"
100 #define XMLNS_XLINK "http://www.w3.org/1999/xlink"
101 #define XMLNS_IMAGE_PREFIX "image:"
102 #define XMLNS_XLINK_PREFIX "xlink:"
104 #define XMLNS_FILTER_SEPARATOR "^"
106 #define IMAGES_DOCTYPE "<!DOCTYPE image:imagecontainer PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"image.dtd\">"
111 struct ImageXMLEntryProperty
113 OReadImagesDocumentHandler::Image_XML_Namespace nNamespace
;
117 ImageXMLEntryProperty ImagesEntries
[OReadImagesDocumentHandler::IMG_XML_ENTRY_COUNT
] =
119 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ELEMENT_IMAGECONTAINER
},
120 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ELEMENT_IMAGES
},
121 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ELEMENT_ENTRY
},
122 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ELEMENT_EXTERNALIMAGES
},
123 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ELEMENT_EXTERNALENTRY
},
124 { OReadImagesDocumentHandler::IMG_NS_XLINK
, ATTRIBUTE_HREF
},
125 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_MASKCOLOR
},
126 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_COMMAND
},
127 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_BITMAPINDEX
},
128 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_MASKURL
},
129 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_MASKMODE
},
130 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_HIGHCONTRASTURL
},
131 { OReadImagesDocumentHandler::IMG_NS_IMAGE
, ATTRIBUTE_HIGHCONTRASTMASKURL
}
135 OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageListsDescriptor
& aItems
) :
136 ThreadHelpBase( &Application::GetSolarMutex() ),
137 m_aImageList( aItems
),
139 m_pExternalImages( 0 )
141 m_aImageList
.pImageList
= NULL
;
142 m_aImageList
.pExternalImageList
= NULL
;
144 m_nHashMaskModeBitmap
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE_BITMAP
)).hashCode();
145 m_nHashMaskModeColor
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE_COLOR
)).hashCode();
147 // create hash map to speed up lookup
148 for ( int i
= 0; i
< (int)IMG_XML_ENTRY_COUNT
; i
++ )
150 ::rtl::OUStringBuffer
temp( 20 );
152 if ( ImagesEntries
[i
].nNamespace
== IMG_NS_IMAGE
)
153 temp
.appendAscii( XMLNS_IMAGE
);
155 temp
.appendAscii( XMLNS_XLINK
);
157 temp
.appendAscii( XMLNS_FILTER_SEPARATOR
);
158 temp
.appendAscii( ImagesEntries
[i
].aEntryName
);
159 m_aImageMap
.insert( ImageHashMap::value_type( temp
.makeStringAndClear(), (Image_XML_Entry
)i
) );
163 m_bImageContainerStartFound
= sal_False
;
164 m_bImageContainerEndFound
= sal_False
;
165 m_bImagesStartFound
= sal_False
;
166 m_bImagesEndFound
= sal_False
;
167 m_bImageStartFound
= sal_False
;
168 m_bExternalImagesStartFound
= sal_False
;
169 m_bExternalImagesEndFound
= sal_False
;
170 m_bExternalImageStartFound
= sal_False
;
173 OReadImagesDocumentHandler::~OReadImagesDocumentHandler()
178 void SAL_CALL
OReadImagesDocumentHandler::startDocument(void)
179 throw ( SAXException
, RuntimeException
)
183 void SAL_CALL
OReadImagesDocumentHandler::endDocument(void)
184 throw( SAXException
, RuntimeException
)
186 ResetableGuard
aGuard( m_aLock
);
188 if (( m_bImageContainerStartFound
&& !m_bImageContainerEndFound
) ||
189 ( !m_bImageContainerStartFound
&& m_bImageContainerEndFound
) )
191 ::rtl::OUString aErrorMessage
= getErrorLineString();
192 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'image:imagecontainer' found!" ));
193 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
197 void SAL_CALL
OReadImagesDocumentHandler::startElement(
198 const ::rtl::OUString
& aName
, const Reference
< XAttributeList
> &xAttribs
)
199 throw( SAXException
, RuntimeException
)
201 ResetableGuard
aGuard( m_aLock
);
203 ImageHashMap::const_iterator pImageEntry
= m_aImageMap
.find( aName
) ;
204 if ( pImageEntry
!= m_aImageMap
.end() )
206 switch ( pImageEntry
->second
)
208 case IMG_ELEMENT_IMAGECONTAINER
:
210 // image:imagecontainer element (container element for all further image elements)
211 if ( m_bImageContainerStartFound
)
213 ::rtl::OUString aErrorMessage
= getErrorLineString();
214 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:imagecontainer' cannot be embeded into 'image:imagecontainer'!" ));
215 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
218 m_bImageContainerStartFound
= sal_True
;
222 case IMG_ELEMENT_IMAGES
:
224 if ( !m_bImageContainerStartFound
)
226 ::rtl::OUString aErrorMessage
= getErrorLineString();
227 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:images' must be embeded into element 'image:imagecontainer'!" ));
228 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
231 if ( m_bImagesStartFound
)
233 ::rtl::OUString aErrorMessage
= getErrorLineString();
234 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:images' cannot be embeded into 'image:images'!" ));
235 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
238 if ( !m_aImageList
.pImageList
)
239 m_aImageList
.pImageList
= new ImageListDescriptor
;
241 m_bImagesStartFound
= sal_True
;
242 m_pImages
= new ImageListItemDescriptor
;
244 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
246 pImageEntry
= m_aImageMap
.find( xAttribs
->getNameByIndex( n
) );
247 if ( pImageEntry
!= m_aImageMap
.end() )
249 switch ( pImageEntry
->second
)
251 case IMG_ATTRIBUTE_HREF
:
253 m_pImages
->aURL
= xAttribs
->getValueByIndex( n
);
257 case IMG_ATTRIBUTE_MASKCOLOR
:
259 ::rtl::OUString aColor
= xAttribs
->getValueByIndex( n
);
261 if ( aColor
.getLength() > 0 )
263 if ( aColor
.getStr()[0] == '#' )
265 // the color value is given as #rrggbb and used the hexadecimal system!!
266 sal_uInt32 nColor
= aColor
.copy( 1 ).toInt32( 16 );
268 m_pImages
->aMaskColor
= Color( COLORDATA_RGB( nColor
) );
274 case IMG_ATTRIBUTE_MASKURL
:
276 m_pImages
->aMaskURL
= xAttribs
->getValueByIndex( n
);
280 case IMG_ATTRIBUTE_MASKMODE
:
282 sal_Int32 nHashCode
= xAttribs
->getValueByIndex( n
).hashCode();
283 if ( nHashCode
== m_nHashMaskModeBitmap
)
284 m_pImages
->nMaskMode
= ImageMaskMode_Bitmap
;
285 else if ( nHashCode
== m_nHashMaskModeColor
)
286 m_pImages
->nMaskMode
= ImageMaskMode_Color
;
292 ::rtl::OUString aErrorMessage
= getErrorLineString();
293 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute image:maskmode must be 'maskcolor' or 'maskbitmap'!" ));
294 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
299 case IMG_ATTRIBUTE_HIGHCONTRASTURL
:
301 m_pImages
->aHighContrastURL
= xAttribs
->getValueByIndex( n
);
305 case IMG_ATTRIBUTE_HIGHCONTRASTMASKURL
:
307 m_pImages
->aHighContrastMaskURL
= xAttribs
->getValueByIndex( n
);
317 if ( m_pImages
->aURL
.Len() == 0 )
322 ::rtl::OUString aErrorMessage
= getErrorLineString();
323 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute xlink:href must have a value!" ));
324 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
329 case IMG_ELEMENT_ENTRY
:
331 // Check that image:entry is embeded into image:images!
332 if ( !m_bImagesStartFound
)
337 ::rtl::OUString aErrorMessage
= getErrorLineString();
338 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:entry' must be embeded into element 'image:images'!" ));
339 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
342 if ( !m_pImages
->pImageItemList
)
343 m_pImages
->pImageItemList
= new ImageItemListDescriptor
;
345 m_bImageStartFound
= sal_True
;
347 // Create new image item descriptor
348 ImageItemDescriptor
* pItem
= new ImageItemDescriptor
;
351 // Read attributes for this image definition
352 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
354 pImageEntry
= m_aImageMap
.find( xAttribs
->getNameByIndex( n
) );
355 if ( pImageEntry
!= m_aImageMap
.end() )
357 switch ( pImageEntry
->second
)
359 case IMG_ATTRIBUTE_COMMAND
:
361 pItem
->aCommandURL
= xAttribs
->getValueByIndex( n
);
365 case IMG_ATTRIBUTE_BITMAPINDEX
:
367 pItem
->nIndex
= xAttribs
->getValueByIndex( n
).toInt32();
377 // Check required attribute "bitmap-index"
378 if ( pItem
->nIndex
< 0 )
384 ::rtl::OUString aErrorMessage
= getErrorLineString();
385 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute 'image:bitmap-index' must have a value >= 0!" ));
386 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
389 // Check required attribute "command"
390 if ( pItem
->aCommandURL
.Len() == 0 )
396 ::rtl::OUString aErrorMessage
= getErrorLineString();
397 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute 'image:command' must have a value!" ));
398 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
402 m_pImages
->pImageItemList
->Insert( pItem
, m_pImages
->pImageItemList
->Count() );
406 case IMG_ELEMENT_EXTERNALIMAGES
:
408 // Check that image:externalimages is embeded into image:imagecontainer
409 if ( !m_bImageContainerStartFound
)
414 ::rtl::OUString aErrorMessage
= getErrorLineString();
415 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:externalimages' must be embeded into element 'image:imagecontainer'!" ));
416 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
419 // Check that image:externalentry is NOT embeded into image:externalentry
420 if ( m_bExternalImagesStartFound
)
425 ::rtl::OUString aErrorMessage
= getErrorLineString();
426 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:externalimages' cannot be embeded into 'image:externalimages'!" ));
427 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
430 // Create unique external image container
431 m_bExternalImagesStartFound
= sal_True
;
432 m_pExternalImages
= new ExternalImageItemListDescriptor
;
436 case IMG_ELEMENT_EXTERNALENTRY
:
438 if ( !m_bExternalImagesStartFound
)
441 delete m_pExternalImages
;
443 m_pExternalImages
= NULL
;
445 ::rtl::OUString aErrorMessage
= getErrorLineString();
446 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:externalentry' must be embeded into 'image:externalimages'!" ));
447 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
450 if ( m_bExternalImageStartFound
)
453 delete m_pExternalImages
;
455 m_pExternalImages
= NULL
;
457 ::rtl::OUString aErrorMessage
= getErrorLineString();
458 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'image:externalentry' cannot be embeded into 'image:externalentry'!" ));
459 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
462 m_bExternalImageStartFound
= sal_True
;
464 ExternalImageItemDescriptor
* pItem
= new ExternalImageItemDescriptor
;
466 // Read attributes for this external image definition
467 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
469 pImageEntry
= m_aImageMap
.find( xAttribs
->getNameByIndex( n
) );
470 if ( pImageEntry
!= m_aImageMap
.end() )
472 switch ( pImageEntry
->second
)
474 case IMG_ATTRIBUTE_COMMAND
:
476 pItem
->aCommandURL
= xAttribs
->getValueByIndex( n
);
480 case IMG_ATTRIBUTE_HREF
:
482 pItem
->aURL
= xAttribs
->getValueByIndex( n
);
492 // Check required attribute "command"
493 if ( pItem
->aCommandURL
.Len() == 0 )
497 delete m_pExternalImages
;
499 m_pExternalImages
= NULL
;
501 ::rtl::OUString aErrorMessage
= getErrorLineString();
502 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute 'image:command' must have a value!" ));
503 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
506 // Check required attribute "href"
507 if ( pItem
->aURL
.Len() == 0 )
511 delete m_pExternalImages
;
513 m_pExternalImages
= NULL
;
515 ::rtl::OUString aErrorMessage
= getErrorLineString();
516 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute 'xlink:href' must have a value!" ));
517 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
520 if ( m_pExternalImages
)
521 m_pExternalImages
->Insert( pItem
, m_pExternalImages
->Count() );
531 void SAL_CALL
OReadImagesDocumentHandler::endElement(const ::rtl::OUString
& aName
)
532 throw( SAXException
, RuntimeException
)
534 ResetableGuard
aGuard( m_aLock
);
536 ImageHashMap::const_iterator pImageEntry
= m_aImageMap
.find( aName
) ;
537 if ( pImageEntry
!= m_aImageMap
.end() )
539 switch ( pImageEntry
->second
)
541 case IMG_ELEMENT_IMAGECONTAINER
:
543 m_bImageContainerEndFound
= sal_True
;
547 case IMG_ELEMENT_IMAGES
:
551 if ( m_aImageList
.pImageList
)
552 m_aImageList
.pImageList
->Insert( m_pImages
, m_aImageList
.pImageList
->Count() );
555 m_bImagesStartFound
= sal_False
;
559 case IMG_ELEMENT_ENTRY
:
561 m_bImageStartFound
= sal_False
;
565 case IMG_ELEMENT_EXTERNALIMAGES
:
567 if ( m_pExternalImages
&& !m_aImageList
.pExternalImageList
)
569 if ( !m_aImageList
.pExternalImageList
)
570 m_aImageList
.pExternalImageList
= m_pExternalImages
;
573 m_bExternalImagesStartFound
= sal_False
;
574 m_pExternalImages
= NULL
;
578 case IMG_ELEMENT_EXTERNALENTRY
:
580 m_bExternalImageStartFound
= sal_False
;
590 void SAL_CALL
OReadImagesDocumentHandler::characters(const ::rtl::OUString
&)
591 throw( SAXException
, RuntimeException
)
595 void SAL_CALL
OReadImagesDocumentHandler::ignorableWhitespace(const ::rtl::OUString
&)
596 throw( SAXException
, RuntimeException
)
600 void SAL_CALL
OReadImagesDocumentHandler::processingInstruction(
601 const ::rtl::OUString
& /*aTarget*/, const ::rtl::OUString
& /*aData*/ )
602 throw( SAXException
, RuntimeException
)
606 void SAL_CALL
OReadImagesDocumentHandler::setDocumentLocator(
607 const Reference
< XLocator
> &xLocator
)
608 throw( SAXException
, RuntimeException
)
610 ResetableGuard
aGuard( m_aLock
);
612 m_xLocator
= xLocator
;
615 ::rtl::OUString
OReadImagesDocumentHandler::getErrorLineString()
617 ResetableGuard
aGuard( m_aLock
);
621 if ( m_xLocator
.is() )
623 snprintf( buffer
, sizeof(buffer
), "Line: %ld - ", static_cast<long>( m_xLocator
->getLineNumber() ));
624 return ::rtl::OUString::createFromAscii( buffer
);
627 return ::rtl::OUString();
631 //_________________________________________________________________________________________________________________
632 // OWriteImagesDocumentHandler
633 //_________________________________________________________________________________________________________________
635 OWriteImagesDocumentHandler::OWriteImagesDocumentHandler(
636 const ImageListsDescriptor
& aItems
,
637 Reference
< XDocumentHandler
> rWriteDocumentHandler
) :
638 ThreadHelpBase( &Application::GetSolarMutex() ),
639 m_aImageListsItems( aItems
),
640 m_xWriteDocumentHandler( rWriteDocumentHandler
)
642 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
643 m_xEmptyList
= Reference
< XAttributeList
>( (XAttributeList
*) pList
, UNO_QUERY
);
644 m_aAttributeType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA
));
645 m_aXMLImageNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_IMAGE_PREFIX
));
646 m_aXMLXlinkNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX
));
647 m_aAttributeXlinkType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XLINK_TYPE
));
648 m_aAttributeValueSimple
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XLINK_TYPE_VALUE
));
651 OWriteImagesDocumentHandler::~OWriteImagesDocumentHandler()
655 void OWriteImagesDocumentHandler::WriteImagesDocument() throw
656 ( SAXException
, RuntimeException
)
658 ResetableGuard
aGuard( m_aLock
);
660 m_xWriteDocumentHandler
->startDocument();
662 // write DOCTYPE line!
663 Reference
< XExtendedDocumentHandler
> xExtendedDocHandler( m_xWriteDocumentHandler
, UNO_QUERY
);
664 if ( xExtendedDocHandler
.is() )
666 xExtendedDocHandler
->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMAGES_DOCTYPE
)) );
667 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
670 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
671 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
673 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_IMAGE
)),
675 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_IMAGE
)) );
677 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK
)),
679 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK
)) );
681 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_IMAGESCONTAINER
)), pList
);
682 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
684 if ( m_aImageListsItems
.pImageList
)
686 ImageListDescriptor
* pImageList
= m_aImageListsItems
.pImageList
;
688 for ( USHORT i
= 0; i
< m_aImageListsItems
.pImageList
->Count(); i
++ )
690 const ImageListItemDescriptor
* pImageItems
= (*pImageList
)[i
];
691 WriteImageList( pImageItems
);
695 if ( m_aImageListsItems
.pExternalImageList
)
697 WriteExternalImageList( m_aImageListsItems
.pExternalImageList
);
700 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
701 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_IMAGESCONTAINER
)) );
702 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
703 m_xWriteDocumentHandler
->endDocument();
706 //_________________________________________________________________________________________________________________
707 // protected member functions
708 //_________________________________________________________________________________________________________________
710 void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor
* pImageList
) throw
711 ( SAXException
, RuntimeException
)
713 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
714 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
716 // save required attributes
717 pList
->AddAttribute( m_aAttributeXlinkType
,
719 m_aAttributeValueSimple
);
721 pList
->AddAttribute( m_aXMLXlinkNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HREF
)),
725 if ( pImageList
->nMaskMode
== ImageMaskMode_Bitmap
)
727 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE
)),
729 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE_BITMAP
)) );
731 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKURL
)),
733 pImageList
->aMaskURL
);
735 if ( pImageList
->aHighContrastMaskURL
.Len() > 0 )
737 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HIGHCONTRASTMASKURL
)),
739 pImageList
->aHighContrastMaskURL
);
744 ::rtl::OUStringBuffer
aColorStrBuffer( 8 );
745 sal_Int64 nValue
= pImageList
->aMaskColor
.GetRGBColor();
747 aColorStrBuffer
.appendAscii( "#" );
748 aColorStrBuffer
.append( ::rtl::OUString::valueOf( nValue
, 16 ));
750 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKCOLOR
)),
752 aColorStrBuffer
.makeStringAndClear() );
754 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE
)),
756 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MASKMODE_COLOR
)) );
759 if ( pImageList
->aHighContrastURL
.Len() > 0 )
761 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HIGHCONTRASTURL
)),
763 pImageList
->aHighContrastURL
);
766 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_IMAGES
)), xList
);
767 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
769 ImageItemListDescriptor
* pImageItemList
= pImageList
->pImageItemList
;
770 if ( pImageItemList
)
772 for ( USHORT i
= 0; i
< pImageItemList
->Count(); i
++ )
773 WriteImage( (*pImageItemList
)[i
] );
776 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_IMAGES
)) );
777 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
780 void OWriteImagesDocumentHandler::WriteImage( const ImageItemDescriptor
* pImage
) throw
781 ( SAXException
, RuntimeException
)
783 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
784 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
786 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BITMAPINDEX
)),
788 ::rtl::OUString::valueOf( (sal_Int32
)pImage
->nIndex
) );
790 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_COMMAND
)),
792 pImage
->aCommandURL
);
794 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_ENTRY
)), xList
);
795 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
797 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_ENTRY
)) );
798 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
801 void OWriteImagesDocumentHandler::WriteExternalImageList( const ExternalImageItemListDescriptor
* pExternalImageList
) throw
802 ( SAXException
, RuntimeException
)
804 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EXTERNALIMAGES
)), m_xEmptyList
);
805 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
807 for ( USHORT i
= 0; i
< pExternalImageList
->Count(); i
++ )
809 ExternalImageItemDescriptor
* pItem
= (*pExternalImageList
)[i
];
810 WriteExternalImage( pItem
);
813 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
814 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EXTERNALIMAGES
)) );
815 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
818 void OWriteImagesDocumentHandler::WriteExternalImage( const ExternalImageItemDescriptor
* pExternalImage
) throw
819 ( SAXException
, RuntimeException
)
821 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
822 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
824 // save required attributes
825 pList
->AddAttribute( m_aAttributeXlinkType
,
827 m_aAttributeValueSimple
);
829 if ( pExternalImage
->aURL
.Len() > 0 )
831 pList
->AddAttribute( m_aXMLXlinkNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HREF
)),
833 pExternalImage
->aURL
);
836 if ( pExternalImage
->aCommandURL
.Len() > 0 )
838 pList
->AddAttribute( m_aXMLImageNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_COMMAND
)),
840 pExternalImage
->aCommandURL
);
843 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EXTERNALENTRY
)), xList
);
844 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
846 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EXTERNALENTRY
)) );
847 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
850 } // namespace framework