LCOV - code coverage report
Current view: top level - framework/source/xml - imagesdocumenthandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 353 0.0 %
Date: 2014-04-11 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : 
      22             : #include <xml/imagesdocumenthandler.hxx>
      23             : 
      24             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      25             : 
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/toolbox.hxx>
      28             : #include <rtl/ustrbuf.hxx>
      29             : 
      30             : #include <comphelper/attributelist.hxx>
      31             : 
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::xml::sax;
      34             : 
      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"
      40             : 
      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"
      46             : 
      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"
      56             : 
      57             : #define ATTRIBUTE_MASKMODE_BITMAP   "maskbitmap"
      58             : #define ATTRIBUTE_MASKMODE_COLOR    "maskcolor"
      59             : 
      60             : #define ATTRIBUTE_XMLNS_IMAGE       "xmlns:image"
      61             : #define ATTRIBUTE_XMLNS_XLINK       "xmlns:xlink"
      62             : 
      63             : #define ATTRIBUTE_XLINK_TYPE        "xlink:type"
      64             : #define ATTRIBUTE_XLINK_TYPE_VALUE  "simple"
      65             : 
      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:"
      70             : 
      71             : #define XMLNS_FILTER_SEPARATOR      "^"
      72             : 
      73             : #define IMAGES_DOCTYPE  "<!DOCTYPE image:imagecontainer PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"image.dtd\">"
      74             : 
      75             : namespace framework
      76             : {
      77             : 
      78             : struct ImageXMLEntryProperty
      79             : {
      80             :     OReadImagesDocumentHandler::Image_XML_Namespace nNamespace;
      81             :     char                                            aEntryName[20];
      82             : };
      83             : 
      84             : ImageXMLEntryProperty ImagesEntries[OReadImagesDocumentHandler::IMG_XML_ENTRY_COUNT] =
      85             : {
      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   }
      99             : };
     100             : 
     101           0 : OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageListsDescriptor& aItems ) :
     102             :     m_aImageList( aItems ),
     103             :     m_pImages( 0 ),
     104           0 :     m_pExternalImages( 0 )
     105             : {
     106           0 :     m_aImageList.pImageList         = NULL;
     107           0 :     m_aImageList.pExternalImageList = NULL;
     108             : 
     109           0 :     m_nHashMaskModeBitmap   = OUString( ATTRIBUTE_MASKMODE_BITMAP ).hashCode();
     110           0 :     m_nHashMaskModeColor    = OUString( ATTRIBUTE_MASKMODE_COLOR ).hashCode();
     111             : 
     112             :     // create hash map to speed up lookup
     113           0 :     for ( int i = 0; i < (int)IMG_XML_ENTRY_COUNT; i++ )
     114             :     {
     115           0 :         OUStringBuffer temp( 20 );
     116             : 
     117           0 :         if ( ImagesEntries[i].nNamespace == IMG_NS_IMAGE )
     118           0 :             temp.appendAscii( XMLNS_IMAGE );
     119             :         else
     120           0 :             temp.appendAscii( XMLNS_XLINK );
     121             : 
     122           0 :         temp.appendAscii( XMLNS_FILTER_SEPARATOR );
     123           0 :         temp.appendAscii( ImagesEntries[i].aEntryName );
     124           0 :         m_aImageMap.insert( ImageHashMap::value_type( temp.makeStringAndClear(), (Image_XML_Entry)i ) );
     125           0 :     }
     126             : 
     127             :     // reset states
     128           0 :     m_bImageContainerStartFound     = false;
     129           0 :     m_bImageContainerEndFound       = false;
     130           0 :     m_bImagesStartFound             = false;
     131           0 :     m_bImagesEndFound               = false;
     132           0 :     m_bImageStartFound              = false;
     133           0 :     m_bExternalImagesStartFound     = false;
     134           0 :     m_bExternalImagesEndFound       = false;
     135           0 :     m_bExternalImageStartFound      = false;
     136           0 : }
     137             : 
     138           0 : OReadImagesDocumentHandler::~OReadImagesDocumentHandler()
     139             : {
     140           0 : }
     141             : 
     142             : // XDocumentHandler
     143           0 : void SAL_CALL OReadImagesDocumentHandler::startDocument(void)
     144             : throw ( SAXException, RuntimeException, std::exception )
     145             : {
     146           0 : }
     147             : 
     148           0 : void SAL_CALL OReadImagesDocumentHandler::endDocument(void)
     149             : throw(  SAXException, RuntimeException, std::exception )
     150             : {
     151           0 :     SolarMutexGuard g;
     152             : 
     153           0 :     if (( m_bImageContainerStartFound && !m_bImageContainerEndFound ) ||
     154           0 :         ( !m_bImageContainerStartFound && m_bImageContainerEndFound )    )
     155             :     {
     156           0 :         OUString aErrorMessage = getErrorLineString();
     157           0 :         aErrorMessage += "No matching start or end element 'image:imagecontainer' found!";
     158           0 :         throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     159           0 :     }
     160           0 : }
     161             : 
     162           0 : void SAL_CALL OReadImagesDocumentHandler::startElement(
     163             :     const OUString& aName, const Reference< XAttributeList > &xAttribs )
     164             :         throw(SAXException,
     165             :               RuntimeException,
     166             :               std::exception)
     167             : {
     168           0 :     SolarMutexGuard g;
     169             : 
     170           0 :     ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName );
     171           0 :     if ( pImageEntry != m_aImageMap.end() )
     172             :     {
     173           0 :         switch ( pImageEntry->second )
     174             :         {
     175             :             case IMG_ELEMENT_IMAGECONTAINER:
     176             :             {
     177             :                 // image:imagecontainer element (container element for all further image elements)
     178           0 :                 if ( m_bImageContainerStartFound )
     179             :                 {
     180           0 :                     OUString aErrorMessage = getErrorLineString();
     181           0 :                     aErrorMessage += "Element 'image:imagecontainer' cannot be embeded into 'image:imagecontainer'!";
     182           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     183             :                 }
     184             : 
     185           0 :                 m_bImageContainerStartFound = true;
     186             :             }
     187           0 :             break;
     188             : 
     189             :             case IMG_ELEMENT_IMAGES:
     190             :             {
     191           0 :                 if ( !m_bImageContainerStartFound )
     192             :                 {
     193           0 :                     OUString aErrorMessage = getErrorLineString();
     194           0 :                     aErrorMessage += "Element 'image:images' must be embeded into element 'image:imagecontainer'!";
     195           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     196             :                 }
     197             : 
     198           0 :                 if ( m_bImagesStartFound )
     199             :                 {
     200           0 :                     OUString aErrorMessage = getErrorLineString();
     201           0 :                     aErrorMessage += "Element 'image:images' cannot be embeded into 'image:images'!";
     202           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     203             :                 }
     204             : 
     205           0 :                 if ( !m_aImageList.pImageList )
     206           0 :                     m_aImageList.pImageList = new ImageListDescriptor;
     207             : 
     208           0 :                 m_bImagesStartFound = true;
     209           0 :                 m_pImages = new ImageListItemDescriptor;
     210             : 
     211           0 :                 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
     212             :                 {
     213           0 :                     pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
     214           0 :                     if ( pImageEntry != m_aImageMap.end() )
     215             :                     {
     216           0 :                         switch ( pImageEntry->second )
     217             :                         {
     218             :                             case IMG_ATTRIBUTE_HREF:
     219             :                             {
     220           0 :                                 m_pImages->aURL = xAttribs->getValueByIndex( n );
     221             :                             }
     222           0 :                             break;
     223             : 
     224             :                             case IMG_ATTRIBUTE_MASKCOLOR:
     225             :                             {
     226           0 :                                 OUString aColor = xAttribs->getValueByIndex( n );
     227             : 
     228           0 :                                 if ( aColor.startsWith("#") )
     229             :                                 {
     230             :                                     // the color value is given as #rrggbb and used the hexadecimal system!!
     231           0 :                                     sal_uInt32 nColor = aColor.copy( 1 ).toUInt32( 16 );
     232             : 
     233           0 :                                     m_pImages->aMaskColor = Color( COLORDATA_RGB( nColor ) );
     234           0 :                                 }
     235             :                             }
     236           0 :                             break;
     237             : 
     238             :                             case IMG_ATTRIBUTE_MASKURL:
     239             :                             {
     240           0 :                                 m_pImages->aMaskURL = xAttribs->getValueByIndex( n );
     241             :                             }
     242           0 :                             break;
     243             : 
     244             :                             case IMG_ATTRIBUTE_MASKMODE:
     245             :                             {
     246           0 :                                 sal_Int32 nHashCode = xAttribs->getValueByIndex( n ).hashCode();
     247           0 :                                 if ( nHashCode == m_nHashMaskModeBitmap )
     248           0 :                                     m_pImages->nMaskMode = ImageMaskMode_Bitmap;
     249           0 :                                 else if ( nHashCode == m_nHashMaskModeColor )
     250           0 :                                     m_pImages->nMaskMode = ImageMaskMode_Color;
     251             :                                 else
     252             :                                 {
     253           0 :                                     delete m_pImages;
     254           0 :                                     m_pImages = NULL;
     255             : 
     256           0 :                                     OUString aErrorMessage = getErrorLineString();
     257           0 :                                     aErrorMessage += "Attribute image:maskmode must be 'maskcolor' or 'maskbitmap'!";
     258           0 :                                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     259             :                                 }
     260             :                             }
     261           0 :                             break;
     262             : 
     263             :                             case IMG_ATTRIBUTE_HIGHCONTRASTURL:
     264             :                             {
     265           0 :                                 m_pImages->aHighContrastURL = xAttribs->getValueByIndex( n );
     266             :                             }
     267           0 :                             break;
     268             : 
     269             :                             case IMG_ATTRIBUTE_HIGHCONTRASTMASKURL:
     270             :                             {
     271           0 :                                 m_pImages->aHighContrastMaskURL = xAttribs->getValueByIndex( n );
     272             :                             }
     273           0 :                             break;
     274             : 
     275             :                                           default:
     276           0 :                                               break;
     277             :                         }
     278             :                     }
     279             :                 } // for
     280             : 
     281           0 :                 if ( m_pImages->aURL.isEmpty() )
     282             :                 {
     283           0 :                     delete m_pImages;
     284           0 :                     m_pImages = NULL;
     285             : 
     286           0 :                     OUString aErrorMessage = getErrorLineString();
     287           0 :                     aErrorMessage += "Required attribute xlink:href must have a value!";
     288           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     289             :                 }
     290             :             }
     291           0 :             break;
     292             : 
     293             :             case IMG_ELEMENT_ENTRY:
     294             :             {
     295             :                 // Check that image:entry is embeded into image:images!
     296           0 :                 if ( !m_bImagesStartFound )
     297             :                 {
     298           0 :                     delete m_pImages;
     299           0 :                     m_pImages = NULL;
     300             : 
     301           0 :                     OUString aErrorMessage = getErrorLineString();
     302           0 :                     aErrorMessage += "Element 'image:entry' must be embeded into element 'image:images'!";
     303           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     304             :                 }
     305             : 
     306           0 :                 if ( !m_pImages->pImageItemList )
     307           0 :                     m_pImages->pImageItemList = new ImageItemListDescriptor;
     308             : 
     309           0 :                 m_bImageStartFound = true;
     310             : 
     311             :                 // Create new image item descriptor
     312           0 :                 ImageItemDescriptor* pItem = new ImageItemDescriptor;
     313           0 :                 pItem->nIndex = -1;
     314             : 
     315             :                 // Read attributes for this image definition
     316           0 :                 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
     317             :                 {
     318           0 :                     pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
     319           0 :                     if ( pImageEntry != m_aImageMap.end() )
     320             :                     {
     321           0 :                         switch ( pImageEntry->second )
     322             :                         {
     323             :                             case IMG_ATTRIBUTE_COMMAND:
     324             :                             {
     325           0 :                                 pItem->aCommandURL  = xAttribs->getValueByIndex( n );
     326             :                             }
     327           0 :                             break;
     328             : 
     329             :                             case IMG_ATTRIBUTE_BITMAPINDEX:
     330             :                             {
     331           0 :                                 pItem->nIndex       = xAttribs->getValueByIndex( n ).toInt32();
     332             :                             }
     333           0 :                             break;
     334             : 
     335             :                                           default:
     336           0 :                                               break;
     337             :                         }
     338             :                     }
     339             :                 }
     340             : 
     341             :                 // Check required attribute "bitmap-index"
     342           0 :                 if ( pItem->nIndex < 0 )
     343             :                 {
     344           0 :                     delete pItem;
     345           0 :                     delete m_pImages;
     346           0 :                     m_pImages = NULL;
     347             : 
     348           0 :                     OUString aErrorMessage = getErrorLineString();
     349           0 :                     aErrorMessage += "Required attribute 'image:bitmap-index' must have a value >= 0!";
     350           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     351             :                 }
     352             : 
     353             :                 // Check required attribute "command"
     354           0 :                 if ( pItem->aCommandURL.isEmpty() )
     355             :                 {
     356           0 :                     delete pItem;
     357           0 :                     delete m_pImages;
     358           0 :                     m_pImages = NULL;
     359             : 
     360           0 :                     OUString aErrorMessage = getErrorLineString();
     361           0 :                     aErrorMessage += "Required attribute 'image:command' must have a value!";
     362           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     363             :                 }
     364             : 
     365           0 :                 if ( m_pImages )
     366           0 :                     m_pImages->pImageItemList->push_back( pItem );
     367             :             }
     368           0 :             break;
     369             : 
     370             :             case IMG_ELEMENT_EXTERNALIMAGES:
     371             :             {
     372             :                 // Check that image:externalimages is embeded into image:imagecontainer
     373           0 :                 if ( !m_bImageContainerStartFound )
     374             :                 {
     375           0 :                     delete m_pImages;
     376           0 :                     m_pImages = NULL;
     377             : 
     378           0 :                     OUString aErrorMessage = getErrorLineString();
     379           0 :                     aErrorMessage += "Element 'image:externalimages' must be embeded into element 'image:imagecontainer'!";
     380           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     381             :                 }
     382             : 
     383             :                 // Check that image:externalentry is NOT embeded into image:externalentry
     384           0 :                 if ( m_bExternalImagesStartFound )
     385             :                 {
     386           0 :                     delete m_pImages;
     387           0 :                     m_pImages = NULL;
     388             : 
     389           0 :                     OUString aErrorMessage = getErrorLineString();
     390           0 :                     aErrorMessage += "Element 'image:externalimages' cannot be embeded into 'image:externalimages'!";
     391           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     392             :                 }
     393             : 
     394             :                 // Create unique external image container
     395           0 :                 m_bExternalImagesStartFound = true;
     396           0 :                 m_pExternalImages = new ExternalImageItemListDescriptor;
     397             :             }
     398           0 :             break;
     399             : 
     400             :             case IMG_ELEMENT_EXTERNALENTRY:
     401             :             {
     402           0 :                 if ( !m_bExternalImagesStartFound )
     403             :                 {
     404           0 :                     delete m_pImages;
     405           0 :                     delete m_pExternalImages;
     406           0 :                     m_pImages = NULL;
     407           0 :                     m_pExternalImages = NULL;
     408             : 
     409           0 :                     OUString aErrorMessage = getErrorLineString();
     410           0 :                     aErrorMessage += "Element 'image:externalentry' must be embeded into 'image:externalimages'!";
     411           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     412             :                 }
     413             : 
     414           0 :                 if ( m_bExternalImageStartFound )
     415             :                 {
     416           0 :                     delete m_pImages;
     417           0 :                     delete m_pExternalImages;
     418           0 :                     m_pImages = NULL;
     419           0 :                     m_pExternalImages = NULL;
     420             : 
     421           0 :                     OUString aErrorMessage = getErrorLineString();
     422           0 :                     aErrorMessage += "Element 'image:externalentry' cannot be embeded into 'image:externalentry'!";
     423           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     424             :                 }
     425             : 
     426           0 :                 m_bExternalImageStartFound = true;
     427             : 
     428           0 :                 ExternalImageItemDescriptor* pItem = new ExternalImageItemDescriptor;
     429             : 
     430             :                 // Read attributes for this external image definition
     431           0 :                 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
     432             :                 {
     433           0 :                     pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
     434           0 :                     if ( pImageEntry != m_aImageMap.end() )
     435             :                     {
     436           0 :                         switch ( pImageEntry->second )
     437             :                         {
     438             :                             case IMG_ATTRIBUTE_COMMAND:
     439             :                             {
     440           0 :                                 pItem->aCommandURL  = xAttribs->getValueByIndex( n );
     441             :                             }
     442           0 :                             break;
     443             : 
     444             :                             case IMG_ATTRIBUTE_HREF:
     445             :                             {
     446           0 :                                 pItem->aURL         = xAttribs->getValueByIndex( n );
     447             :                             }
     448           0 :                             break;
     449             : 
     450             :                                           default:
     451           0 :                                               break;
     452             :                         }
     453             :                     }
     454             :                 }
     455             : 
     456             :                 // Check required attribute "command"
     457           0 :                 if ( pItem->aCommandURL.isEmpty() )
     458             :                 {
     459           0 :                     delete pItem;
     460           0 :                     delete m_pImages;
     461           0 :                     delete m_pExternalImages;
     462           0 :                     m_pImages = NULL;
     463           0 :                     m_pExternalImages = NULL;
     464             : 
     465           0 :                     OUString aErrorMessage = getErrorLineString();
     466           0 :                     aErrorMessage += "Required attribute 'image:command' must have a value!";
     467           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     468             :                 }
     469             : 
     470             :                 // Check required attribute "href"
     471           0 :                 if ( pItem->aURL.isEmpty() )
     472             :                 {
     473           0 :                     delete pItem;
     474           0 :                     delete m_pImages;
     475           0 :                     delete m_pExternalImages;
     476           0 :                     m_pImages = NULL;
     477           0 :                     m_pExternalImages = NULL;
     478             : 
     479           0 :                     OUString aErrorMessage = getErrorLineString();
     480           0 :                     aErrorMessage += "Required attribute 'xlink:href' must have a value!";
     481           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     482             :                 }
     483             : 
     484           0 :                 if ( m_pExternalImages )
     485           0 :                     m_pExternalImages->push_back( pItem );
     486             :                 else
     487           0 :                     delete pItem;
     488             :             }
     489           0 :             break;
     490             : 
     491             :                   default:
     492           0 :                       break;
     493             :         }
     494           0 :     }
     495           0 : }
     496             : 
     497           0 : void SAL_CALL OReadImagesDocumentHandler::endElement(const OUString& aName)
     498             :     throw(SAXException,
     499             :           RuntimeException,
     500             :           std::exception)
     501             : {
     502           0 :     SolarMutexGuard g;
     503             : 
     504           0 :     ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName );
     505           0 :     if ( pImageEntry != m_aImageMap.end() )
     506             :     {
     507           0 :         switch ( pImageEntry->second )
     508             :         {
     509             :             case IMG_ELEMENT_IMAGECONTAINER:
     510             :             {
     511           0 :                 m_bImageContainerEndFound = true;
     512             :             }
     513           0 :             break;
     514             : 
     515             :             case IMG_ELEMENT_IMAGES:
     516             :             {
     517           0 :                 if ( m_pImages )
     518             :                 {
     519           0 :                     if ( m_aImageList.pImageList )
     520           0 :                         m_aImageList.pImageList->push_back( m_pImages );
     521           0 :                     m_pImages = NULL;
     522             :                 }
     523           0 :                 m_bImagesStartFound = false;
     524             :             }
     525           0 :             break;
     526             : 
     527             :             case IMG_ELEMENT_ENTRY:
     528             :             {
     529           0 :                 m_bImageStartFound = false;
     530             :             }
     531           0 :             break;
     532             : 
     533             :             case IMG_ELEMENT_EXTERNALIMAGES:
     534             :             {
     535           0 :                 if ( m_pExternalImages && !m_aImageList.pExternalImageList )
     536             :                 {
     537           0 :                     if ( !m_aImageList.pExternalImageList )
     538           0 :                         m_aImageList.pExternalImageList = m_pExternalImages;
     539             :                 }
     540             : 
     541           0 :                 m_bExternalImagesStartFound = false;
     542           0 :                 m_pExternalImages = NULL;
     543             :             }
     544           0 :             break;
     545             : 
     546             :             case IMG_ELEMENT_EXTERNALENTRY:
     547             :             {
     548           0 :                 m_bExternalImageStartFound = false;
     549             :             }
     550           0 :             break;
     551             : 
     552             :                   default:
     553           0 :                       break;
     554             :         }
     555           0 :     }
     556           0 : }
     557             : 
     558           0 : void SAL_CALL OReadImagesDocumentHandler::characters(const OUString&)
     559             : throw(  SAXException, RuntimeException, std::exception )
     560             : {
     561           0 : }
     562             : 
     563           0 : void SAL_CALL OReadImagesDocumentHandler::ignorableWhitespace(const OUString&)
     564             : throw(  SAXException, RuntimeException, std::exception )
     565             : {
     566           0 : }
     567             : 
     568           0 : void SAL_CALL OReadImagesDocumentHandler::processingInstruction(
     569             :     const OUString& /*aTarget*/, const OUString& /*aData*/ )
     570             : throw(  SAXException, RuntimeException, std::exception )
     571             : {
     572           0 : }
     573             : 
     574           0 : void SAL_CALL OReadImagesDocumentHandler::setDocumentLocator(
     575             :     const Reference< XLocator > &xLocator)
     576             : throw(  SAXException, RuntimeException, std::exception )
     577             : {
     578           0 :     SolarMutexGuard g;
     579           0 :     m_xLocator = xLocator;
     580           0 : }
     581             : 
     582           0 : OUString OReadImagesDocumentHandler::getErrorLineString()
     583             : {
     584           0 :     SolarMutexGuard g;
     585           0 :     if ( m_xLocator.is() )
     586             :     {
     587           0 :         OUStringBuffer buffer("Line: ");
     588           0 :         buffer.append(m_xLocator->getLineNumber());
     589           0 :         buffer.append(" - ");
     590           0 :         return buffer.makeStringAndClear();
     591             :     }
     592             :     else
     593           0 :         return OUString();
     594             : }
     595             : 
     596             : //  OWriteImagesDocumentHandler
     597             : 
     598           0 : OWriteImagesDocumentHandler::OWriteImagesDocumentHandler(
     599             :     const ImageListsDescriptor& aItems,
     600             :     Reference< XDocumentHandler > rWriteDocumentHandler ) :
     601             :     m_aImageListsItems( aItems ),
     602           0 :     m_xWriteDocumentHandler( rWriteDocumentHandler )
     603             : {
     604           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     605           0 :     m_xEmptyList            = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
     606           0 :     m_aAttributeType        = OUString( ATTRIBUTE_TYPE_CDATA );
     607           0 :     m_aXMLImageNS           = OUString( XMLNS_IMAGE_PREFIX );
     608           0 :     m_aXMLXlinkNS           = OUString( XMLNS_XLINK_PREFIX );
     609           0 :     m_aAttributeXlinkType   = OUString( ATTRIBUTE_XLINK_TYPE );
     610           0 :     m_aAttributeValueSimple = OUString( ATTRIBUTE_XLINK_TYPE_VALUE );
     611           0 : }
     612             : 
     613           0 : OWriteImagesDocumentHandler::~OWriteImagesDocumentHandler()
     614             : {
     615           0 : }
     616             : 
     617           0 : void OWriteImagesDocumentHandler::WriteImagesDocument() throw
     618             : ( SAXException, RuntimeException )
     619             : {
     620           0 :     SolarMutexGuard g;
     621             : 
     622           0 :     m_xWriteDocumentHandler->startDocument();
     623             : 
     624             :     // write DOCTYPE line!
     625           0 :     Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
     626           0 :     if ( xExtendedDocHandler.is() )
     627             :     {
     628           0 :         xExtendedDocHandler->unknown( OUString( IMAGES_DOCTYPE ) );
     629           0 :         m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     630             :     }
     631             : 
     632           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     633           0 :     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
     634             : 
     635             :     pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_IMAGE),
     636             :                          m_aAttributeType,
     637           0 :                          OUString( XMLNS_IMAGE ) );
     638             : 
     639             :     pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_XLINK ),
     640             :                          m_aAttributeType,
     641           0 :                          OUString( XMLNS_XLINK ) );
     642             : 
     643           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGESCONTAINER ), pList );
     644           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     645             : 
     646           0 :     if ( m_aImageListsItems.pImageList )
     647             :     {
     648           0 :         ImageListDescriptor* pImageList = m_aImageListsItems.pImageList;
     649             : 
     650           0 :         for ( sal_uInt16 i = 0; i < m_aImageListsItems.pImageList->size(); i++ )
     651             :         {
     652           0 :             const ImageListItemDescriptor* pImageItems = &(*pImageList)[i];
     653           0 :             WriteImageList( pImageItems );
     654             :         }
     655             :     }
     656             : 
     657           0 :     if ( m_aImageListsItems.pExternalImageList )
     658             :     {
     659           0 :         WriteExternalImageList( m_aImageListsItems.pExternalImageList );
     660             :     }
     661             : 
     662           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     663           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGESCONTAINER ) );
     664           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     665           0 :     m_xWriteDocumentHandler->endDocument();
     666           0 : }
     667             : 
     668             : //  protected member functions
     669             : 
     670           0 : void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* pImageList ) throw
     671             : ( SAXException, RuntimeException )
     672             : {
     673           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     674           0 :     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
     675             : 
     676             :     // save required attributes
     677             :     pList->AddAttribute( m_aAttributeXlinkType,
     678             :                          m_aAttributeType,
     679           0 :                          m_aAttributeValueSimple );
     680             : 
     681           0 :     pList->AddAttribute( m_aXMLXlinkNS + OUString( ATTRIBUTE_HREF ),
     682             :                          m_aAttributeType,
     683           0 :                          pImageList->aURL );
     684             : 
     685           0 :     if ( pImageList->nMaskMode == ImageMaskMode_Bitmap )
     686             :     {
     687           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKMODE ),
     688             :                              m_aAttributeType,
     689           0 :                              OUString( ATTRIBUTE_MASKMODE_BITMAP ) );
     690             : 
     691           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKURL ),
     692             :                              m_aAttributeType,
     693           0 :                              pImageList->aMaskURL );
     694             : 
     695           0 :         if ( !pImageList->aHighContrastMaskURL.isEmpty() )
     696             :         {
     697           0 :             pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_HIGHCONTRASTMASKURL ),
     698             :                                  m_aAttributeType,
     699           0 :                                  pImageList->aHighContrastMaskURL );
     700             :         }
     701             :     }
     702             :     else
     703             :     {
     704           0 :         OUStringBuffer   aColorStrBuffer( 8 );
     705           0 :         sal_Int64       nValue = pImageList->aMaskColor.GetRGBColor();
     706             : 
     707           0 :         aColorStrBuffer.appendAscii( "#" );
     708           0 :         aColorStrBuffer.append( OUString::number( nValue, 16 ));
     709             : 
     710           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKCOLOR ),
     711             :                              m_aAttributeType,
     712           0 :                              aColorStrBuffer.makeStringAndClear() );
     713             : 
     714           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_MASKMODE ),
     715             :                              m_aAttributeType,
     716           0 :                              OUString( ATTRIBUTE_MASKMODE_COLOR ) );
     717             :     }
     718             : 
     719           0 :     if ( !pImageList->aHighContrastURL.isEmpty() )
     720             :     {
     721           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_HIGHCONTRASTURL ),
     722             :                              m_aAttributeType,
     723           0 :                              pImageList->aHighContrastURL );
     724             :     }
     725             : 
     726           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGES ), xList );
     727           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     728             : 
     729           0 :     ImageItemListDescriptor* pImageItemList = pImageList->pImageItemList;
     730           0 :     if ( pImageItemList )
     731             :     {
     732           0 :         for ( sal_uInt16 i = 0; i < pImageItemList->size(); i++ )
     733           0 :             WriteImage( &(*pImageItemList)[i] );
     734             :     }
     735             : 
     736           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGES ) );
     737           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     738           0 : }
     739             : 
     740           0 : void OWriteImagesDocumentHandler::WriteImage( const ImageItemDescriptor* pImage ) throw
     741             : ( SAXException, RuntimeException )
     742             : {
     743           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     744           0 :     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
     745             : 
     746           0 :     pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_BITMAPINDEX ),
     747             :                          m_aAttributeType,
     748           0 :                          OUString::number( pImage->nIndex ) );
     749             : 
     750           0 :     pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_COMMAND ),
     751             :                          m_aAttributeType,
     752           0 :                          pImage->aCommandURL );
     753             : 
     754           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_ENTRY ), xList );
     755           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     756             : 
     757           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_ENTRY ) );
     758           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     759           0 : }
     760             : 
     761           0 : void OWriteImagesDocumentHandler::WriteExternalImageList( const ExternalImageItemListDescriptor* pExternalImageList ) throw
     762             : ( SAXException, RuntimeException )
     763             : {
     764           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALIMAGES ), m_xEmptyList );
     765           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     766             : 
     767           0 :     for ( sal_uInt16 i = 0; i < pExternalImageList->size(); i++ )
     768             :     {
     769           0 :         const ExternalImageItemDescriptor* pItem = &(*pExternalImageList)[i];
     770           0 :         WriteExternalImage( pItem );
     771             :     }
     772             : 
     773           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     774           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALIMAGES ) );
     775           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     776           0 : }
     777             : 
     778           0 : void OWriteImagesDocumentHandler::WriteExternalImage( const ExternalImageItemDescriptor* pExternalImage ) throw
     779             : ( SAXException, RuntimeException )
     780             : {
     781           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     782           0 :     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
     783             : 
     784             :     // save required attributes
     785             :     pList->AddAttribute( m_aAttributeXlinkType,
     786             :                          m_aAttributeType,
     787           0 :                          m_aAttributeValueSimple );
     788             : 
     789           0 :     if ( !pExternalImage->aURL.isEmpty() )
     790             :     {
     791           0 :         pList->AddAttribute( m_aXMLXlinkNS + OUString( ATTRIBUTE_HREF ),
     792             :                              m_aAttributeType,
     793           0 :                              pExternalImage->aURL );
     794             :     }
     795             : 
     796           0 :     if ( !pExternalImage->aCommandURL.isEmpty() )
     797             :     {
     798           0 :         pList->AddAttribute( m_aXMLImageNS + OUString( ATTRIBUTE_COMMAND ),
     799             :                              m_aAttributeType,
     800           0 :                              pExternalImage->aCommandURL );
     801             :     }
     802             : 
     803           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALENTRY ), xList );
     804           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     805             : 
     806           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALENTRY ) );
     807           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     808           0 : }
     809             : 
     810             : } // namespace framework
     811             : 
     812             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10