LCOV - code coverage report
Current view: top level - framework/source/xml - imagesdocumenthandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 352 0.0 %
Date: 2015-06-13 12:38:46 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()
     144             : throw ( SAXException, RuntimeException, std::exception )
     145             : {
     146           0 : }
     147             : 
     148           0 : void SAL_CALL OReadImagesDocumentHandler::endDocument()
     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 embedded 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 embedded 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 embedded 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 embedded 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 embedded 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 :                 m_pImages->pImageItemList->push_back( pItem );
     366             :             }
     367           0 :             break;
     368             : 
     369             :             case IMG_ELEMENT_EXTERNALIMAGES:
     370             :             {
     371             :                 // Check that image:externalimages is embedded into image:imagecontainer
     372           0 :                 if ( !m_bImageContainerStartFound )
     373             :                 {
     374           0 :                     delete m_pImages;
     375           0 :                     m_pImages = NULL;
     376             : 
     377           0 :                     OUString aErrorMessage = getErrorLineString();
     378           0 :                     aErrorMessage += "Element 'image:externalimages' must be embedded into element 'image:imagecontainer'!";
     379           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     380             :                 }
     381             : 
     382             :                 // Check that image:externalentry is NOT embedded into image:externalentry
     383           0 :                 if ( m_bExternalImagesStartFound )
     384             :                 {
     385           0 :                     delete m_pImages;
     386           0 :                     m_pImages = NULL;
     387             : 
     388           0 :                     OUString aErrorMessage = getErrorLineString();
     389           0 :                     aErrorMessage += "Element 'image:externalimages' cannot be embedded into 'image:externalimages'!";
     390           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     391             :                 }
     392             : 
     393             :                 // Create unique external image container
     394           0 :                 m_bExternalImagesStartFound = true;
     395           0 :                 m_pExternalImages = new ExternalImageItemListDescriptor;
     396             :             }
     397           0 :             break;
     398             : 
     399             :             case IMG_ELEMENT_EXTERNALENTRY:
     400             :             {
     401           0 :                 if ( !m_bExternalImagesStartFound )
     402             :                 {
     403           0 :                     delete m_pImages;
     404           0 :                     delete m_pExternalImages;
     405           0 :                     m_pImages = NULL;
     406           0 :                     m_pExternalImages = NULL;
     407             : 
     408           0 :                     OUString aErrorMessage = getErrorLineString();
     409           0 :                     aErrorMessage += "Element 'image:externalentry' must be embedded into 'image:externalimages'!";
     410           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     411             :                 }
     412             : 
     413           0 :                 if ( m_bExternalImageStartFound )
     414             :                 {
     415           0 :                     delete m_pImages;
     416           0 :                     delete m_pExternalImages;
     417           0 :                     m_pImages = NULL;
     418           0 :                     m_pExternalImages = NULL;
     419             : 
     420           0 :                     OUString aErrorMessage = getErrorLineString();
     421           0 :                     aErrorMessage += "Element 'image:externalentry' cannot be embedded into 'image:externalentry'!";
     422           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     423             :                 }
     424             : 
     425           0 :                 m_bExternalImageStartFound = true;
     426             : 
     427           0 :                 ExternalImageItemDescriptor* pItem = new ExternalImageItemDescriptor;
     428             : 
     429             :                 // Read attributes for this external image definition
     430           0 :                 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
     431             :                 {
     432           0 :                     pImageEntry = m_aImageMap.find( xAttribs->getNameByIndex( n ) );
     433           0 :                     if ( pImageEntry != m_aImageMap.end() )
     434             :                     {
     435           0 :                         switch ( pImageEntry->second )
     436             :                         {
     437             :                             case IMG_ATTRIBUTE_COMMAND:
     438             :                             {
     439           0 :                                 pItem->aCommandURL  = xAttribs->getValueByIndex( n );
     440             :                             }
     441           0 :                             break;
     442             : 
     443             :                             case IMG_ATTRIBUTE_HREF:
     444             :                             {
     445           0 :                                 pItem->aURL         = xAttribs->getValueByIndex( n );
     446             :                             }
     447           0 :                             break;
     448             : 
     449             :                                           default:
     450           0 :                                               break;
     451             :                         }
     452             :                     }
     453             :                 }
     454             : 
     455             :                 // Check required attribute "command"
     456           0 :                 if ( pItem->aCommandURL.isEmpty() )
     457             :                 {
     458           0 :                     delete pItem;
     459           0 :                     delete m_pImages;
     460           0 :                     delete m_pExternalImages;
     461           0 :                     m_pImages = NULL;
     462           0 :                     m_pExternalImages = NULL;
     463             : 
     464           0 :                     OUString aErrorMessage = getErrorLineString();
     465           0 :                     aErrorMessage += "Required attribute 'image:command' must have a value!";
     466           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     467             :                 }
     468             : 
     469             :                 // Check required attribute "href"
     470           0 :                 if ( pItem->aURL.isEmpty() )
     471             :                 {
     472           0 :                     delete pItem;
     473           0 :                     delete m_pImages;
     474           0 :                     delete m_pExternalImages;
     475           0 :                     m_pImages = NULL;
     476           0 :                     m_pExternalImages = NULL;
     477             : 
     478           0 :                     OUString aErrorMessage = getErrorLineString();
     479           0 :                     aErrorMessage += "Required attribute 'xlink:href' must have a value!";
     480           0 :                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     481             :                 }
     482             : 
     483           0 :                 if ( m_pExternalImages )
     484           0 :                     m_pExternalImages->push_back( pItem );
     485             :                 else
     486           0 :                     delete pItem;
     487             :             }
     488           0 :             break;
     489             : 
     490             :                   default:
     491           0 :                       break;
     492             :         }
     493           0 :     }
     494           0 : }
     495             : 
     496           0 : void SAL_CALL OReadImagesDocumentHandler::endElement(const OUString& aName)
     497             :     throw(SAXException,
     498             :           RuntimeException,
     499             :           std::exception)
     500             : {
     501           0 :     SolarMutexGuard g;
     502             : 
     503           0 :     ImageHashMap::const_iterator pImageEntry = m_aImageMap.find( aName );
     504           0 :     if ( pImageEntry != m_aImageMap.end() )
     505             :     {
     506           0 :         switch ( pImageEntry->second )
     507             :         {
     508             :             case IMG_ELEMENT_IMAGECONTAINER:
     509             :             {
     510           0 :                 m_bImageContainerEndFound = true;
     511             :             }
     512           0 :             break;
     513             : 
     514             :             case IMG_ELEMENT_IMAGES:
     515             :             {
     516           0 :                 if ( m_pImages )
     517             :                 {
     518           0 :                     if ( m_aImageList.pImageList )
     519           0 :                         m_aImageList.pImageList->push_back( m_pImages );
     520           0 :                     m_pImages = NULL;
     521             :                 }
     522           0 :                 m_bImagesStartFound = false;
     523             :             }
     524           0 :             break;
     525             : 
     526             :             case IMG_ELEMENT_ENTRY:
     527             :             {
     528           0 :                 m_bImageStartFound = false;
     529             :             }
     530           0 :             break;
     531             : 
     532             :             case IMG_ELEMENT_EXTERNALIMAGES:
     533             :             {
     534           0 :                 if ( m_pExternalImages && !m_aImageList.pExternalImageList )
     535             :                 {
     536           0 :                     if ( !m_aImageList.pExternalImageList )
     537           0 :                         m_aImageList.pExternalImageList = m_pExternalImages;
     538             :                 }
     539             : 
     540           0 :                 m_bExternalImagesStartFound = false;
     541           0 :                 m_pExternalImages = NULL;
     542             :             }
     543           0 :             break;
     544             : 
     545             :             case IMG_ELEMENT_EXTERNALENTRY:
     546             :             {
     547           0 :                 m_bExternalImageStartFound = false;
     548             :             }
     549           0 :             break;
     550             : 
     551             :                   default:
     552           0 :                       break;
     553             :         }
     554           0 :     }
     555           0 : }
     556             : 
     557           0 : void SAL_CALL OReadImagesDocumentHandler::characters(const OUString&)
     558             : throw(  SAXException, RuntimeException, std::exception )
     559             : {
     560           0 : }
     561             : 
     562           0 : void SAL_CALL OReadImagesDocumentHandler::ignorableWhitespace(const OUString&)
     563             : throw(  SAXException, RuntimeException, std::exception )
     564             : {
     565           0 : }
     566             : 
     567           0 : void SAL_CALL OReadImagesDocumentHandler::processingInstruction(
     568             :     const OUString& /*aTarget*/, const OUString& /*aData*/ )
     569             : throw(  SAXException, RuntimeException, std::exception )
     570             : {
     571           0 : }
     572             : 
     573           0 : void SAL_CALL OReadImagesDocumentHandler::setDocumentLocator(
     574             :     const Reference< XLocator > &xLocator)
     575             : throw(  SAXException, RuntimeException, std::exception )
     576             : {
     577           0 :     SolarMutexGuard g;
     578           0 :     m_xLocator = xLocator;
     579           0 : }
     580             : 
     581           0 : OUString OReadImagesDocumentHandler::getErrorLineString()
     582             : {
     583           0 :     SolarMutexGuard g;
     584           0 :     if ( m_xLocator.is() )
     585             :     {
     586           0 :         OUStringBuffer buffer("Line: ");
     587           0 :         buffer.append(m_xLocator->getLineNumber());
     588           0 :         buffer.append(" - ");
     589           0 :         return buffer.makeStringAndClear();
     590             :     }
     591             :     else
     592           0 :         return OUString();
     593             : }
     594             : 
     595             : //  OWriteImagesDocumentHandler
     596             : 
     597           0 : OWriteImagesDocumentHandler::OWriteImagesDocumentHandler(
     598             :     const ImageListsDescriptor& aItems,
     599             :     Reference< XDocumentHandler > rWriteDocumentHandler ) :
     600             :     m_aImageListsItems( aItems ),
     601           0 :     m_xWriteDocumentHandler( rWriteDocumentHandler )
     602             : {
     603           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     604           0 :     m_xEmptyList            = Reference< XAttributeList >( static_cast<XAttributeList *>(pList), UNO_QUERY );
     605           0 :     m_aAttributeType        = ATTRIBUTE_TYPE_CDATA;
     606           0 :     m_aXMLImageNS           = XMLNS_IMAGE_PREFIX;
     607           0 :     m_aXMLXlinkNS           = XMLNS_XLINK_PREFIX;
     608           0 :     m_aAttributeXlinkType   = ATTRIBUTE_XLINK_TYPE;
     609           0 :     m_aAttributeValueSimple = ATTRIBUTE_XLINK_TYPE_VALUE;
     610           0 : }
     611             : 
     612           0 : OWriteImagesDocumentHandler::~OWriteImagesDocumentHandler()
     613             : {
     614           0 : }
     615             : 
     616           0 : void OWriteImagesDocumentHandler::WriteImagesDocument() throw
     617             : ( SAXException, RuntimeException )
     618             : {
     619           0 :     SolarMutexGuard g;
     620             : 
     621           0 :     m_xWriteDocumentHandler->startDocument();
     622             : 
     623             :     // write DOCTYPE line!
     624           0 :     Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
     625           0 :     if ( xExtendedDocHandler.is() )
     626             :     {
     627           0 :         xExtendedDocHandler->unknown( OUString( IMAGES_DOCTYPE ) );
     628           0 :         m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     629             :     }
     630             : 
     631           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     632           0 :     Reference< XAttributeList > xList( static_cast<XAttributeList *>(pList) , UNO_QUERY );
     633             : 
     634             :     pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_IMAGE),
     635             :                          m_aAttributeType,
     636           0 :                          OUString( XMLNS_IMAGE ) );
     637             : 
     638             :     pList->AddAttribute( OUString( ATTRIBUTE_XMLNS_XLINK ),
     639             :                          m_aAttributeType,
     640           0 :                          OUString( XMLNS_XLINK ) );
     641             : 
     642           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGESCONTAINER ), pList );
     643           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     644             : 
     645           0 :     if ( m_aImageListsItems.pImageList )
     646             :     {
     647           0 :         ImageListDescriptor* pImageList = m_aImageListsItems.pImageList;
     648             : 
     649           0 :         for ( size_t i = 0; i < m_aImageListsItems.pImageList->size(); i++ )
     650             :         {
     651           0 :             const ImageListItemDescriptor* pImageItems = &(*pImageList)[i];
     652           0 :             WriteImageList( pImageItems );
     653             :         }
     654             :     }
     655             : 
     656           0 :     if ( m_aImageListsItems.pExternalImageList )
     657             :     {
     658           0 :         WriteExternalImageList( m_aImageListsItems.pExternalImageList );
     659             :     }
     660             : 
     661           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     662           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGESCONTAINER ) );
     663           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     664           0 :     m_xWriteDocumentHandler->endDocument();
     665           0 : }
     666             : 
     667             : //  protected member functions
     668             : 
     669           0 : void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* pImageList ) throw
     670             : ( SAXException, RuntimeException )
     671             : {
     672           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     673           0 :     Reference< XAttributeList > xList( static_cast<XAttributeList *>(pList) , UNO_QUERY );
     674             : 
     675             :     // save required attributes
     676             :     pList->AddAttribute( m_aAttributeXlinkType,
     677             :                          m_aAttributeType,
     678           0 :                          m_aAttributeValueSimple );
     679             : 
     680           0 :     pList->AddAttribute( m_aXMLXlinkNS + ATTRIBUTE_HREF,
     681             :                          m_aAttributeType,
     682           0 :                          pImageList->aURL );
     683             : 
     684           0 :     if ( pImageList->nMaskMode == ImageMaskMode_Bitmap )
     685             :     {
     686           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKMODE,
     687             :                              m_aAttributeType,
     688           0 :                              OUString( ATTRIBUTE_MASKMODE_BITMAP ) );
     689             : 
     690           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKURL,
     691             :                              m_aAttributeType,
     692           0 :                              pImageList->aMaskURL );
     693             : 
     694           0 :         if ( !pImageList->aHighContrastMaskURL.isEmpty() )
     695             :         {
     696           0 :             pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_HIGHCONTRASTMASKURL,
     697             :                                  m_aAttributeType,
     698           0 :                                  pImageList->aHighContrastMaskURL );
     699             :         }
     700             :     }
     701             :     else
     702             :     {
     703           0 :         OUStringBuffer   aColorStrBuffer( 8 );
     704           0 :         sal_Int64       nValue = pImageList->aMaskColor.GetRGBColor();
     705             : 
     706           0 :         aColorStrBuffer.appendAscii( "#" );
     707           0 :         aColorStrBuffer.append( OUString::number( nValue, 16 ));
     708             : 
     709           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKCOLOR,
     710             :                              m_aAttributeType,
     711           0 :                              aColorStrBuffer.makeStringAndClear() );
     712             : 
     713           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_MASKMODE,
     714             :                              m_aAttributeType,
     715           0 :                              OUString( ATTRIBUTE_MASKMODE_COLOR ) );
     716             :     }
     717             : 
     718           0 :     if ( !pImageList->aHighContrastURL.isEmpty() )
     719             :     {
     720           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_HIGHCONTRASTURL,
     721             :                              m_aAttributeType,
     722           0 :                              pImageList->aHighContrastURL );
     723             :     }
     724             : 
     725           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_IMAGES ), xList );
     726           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     727             : 
     728           0 :     ImageItemListDescriptor* pImageItemList = pImageList->pImageItemList;
     729           0 :     if ( pImageItemList )
     730             :     {
     731           0 :         for ( size_t i = 0; i < pImageItemList->size(); i++ )
     732           0 :             WriteImage( &(*pImageItemList)[i] );
     733             :     }
     734             : 
     735           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_IMAGES ) );
     736           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     737           0 : }
     738             : 
     739           0 : void OWriteImagesDocumentHandler::WriteImage( const ImageItemDescriptor* pImage ) throw
     740             : ( SAXException, RuntimeException )
     741             : {
     742           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     743           0 :     Reference< XAttributeList > xList( static_cast<XAttributeList *>(pList) , UNO_QUERY );
     744             : 
     745           0 :     pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_BITMAPINDEX,
     746             :                          m_aAttributeType,
     747           0 :                          OUString::number( pImage->nIndex ) );
     748             : 
     749           0 :     pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_COMMAND,
     750             :                          m_aAttributeType,
     751           0 :                          pImage->aCommandURL );
     752             : 
     753           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_ENTRY ), xList );
     754           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     755             : 
     756           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_ENTRY ) );
     757           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     758           0 : }
     759             : 
     760           0 : void OWriteImagesDocumentHandler::WriteExternalImageList( const ExternalImageItemListDescriptor* pExternalImageList ) throw
     761             : ( SAXException, RuntimeException )
     762             : {
     763           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALIMAGES ), m_xEmptyList );
     764           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     765             : 
     766           0 :     for ( size_t i = 0; i < pExternalImageList->size(); i++ )
     767             :     {
     768           0 :         const ExternalImageItemDescriptor* pItem = &(*pExternalImageList)[i];
     769           0 :         WriteExternalImage( pItem );
     770             :     }
     771             : 
     772           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     773           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALIMAGES ) );
     774           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     775           0 : }
     776             : 
     777           0 : void OWriteImagesDocumentHandler::WriteExternalImage( const ExternalImageItemDescriptor* pExternalImage ) throw
     778             : ( SAXException, RuntimeException )
     779             : {
     780           0 :     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
     781           0 :     Reference< XAttributeList > xList( static_cast<XAttributeList *>(pList) , UNO_QUERY );
     782             : 
     783             :     // save required attributes
     784             :     pList->AddAttribute( m_aAttributeXlinkType,
     785             :                          m_aAttributeType,
     786           0 :                          m_aAttributeValueSimple );
     787             : 
     788           0 :     if ( !pExternalImage->aURL.isEmpty() )
     789             :     {
     790           0 :         pList->AddAttribute( m_aXMLXlinkNS + ATTRIBUTE_HREF,
     791             :                              m_aAttributeType,
     792           0 :                              pExternalImage->aURL );
     793             :     }
     794             : 
     795           0 :     if ( !pExternalImage->aCommandURL.isEmpty() )
     796             :     {
     797           0 :         pList->AddAttribute( m_aXMLImageNS + ATTRIBUTE_COMMAND,
     798             :                              m_aAttributeType,
     799           0 :                              pExternalImage->aCommandURL );
     800             :     }
     801             : 
     802           0 :     m_xWriteDocumentHandler->startElement( OUString( ELEMENT_NS_EXTERNALENTRY ), xList );
     803           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     804             : 
     805           0 :     m_xWriteDocumentHandler->endElement( OUString( ELEMENT_NS_EXTERNALENTRY ) );
     806           0 :     m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
     807           0 : }
     808             : 
     809             : } // namespace framework
     810             : 
     811             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11