1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <framework/fwedllapi.h> 32*cdf0e10cSrcweir #include <stdio.h> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 35*cdf0e10cSrcweir // my own includes 36*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 39*cdf0e10cSrcweir #include <xml/eventsdocumenthandler.hxx> 40*cdf0e10cSrcweir #include <macros/debug.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43*cdf0e10cSrcweir // interface includes 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_ 47*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // other includes 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <sal/config.h> 55*cdf0e10cSrcweir #include <vcl/svapp.hxx> 56*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <comphelper/attributelist.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61*cdf0e10cSrcweir // namespace 62*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 65*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 66*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #define XMLNS_EVENT "http://openoffice.org/2001/event" 70*cdf0e10cSrcweir #define XMLNS_XLINK "http://www.w3.org/1999/xlink" 71*cdf0e10cSrcweir #define XMLNS_EVENT_PREFIX "event:" 72*cdf0e10cSrcweir #define XMLNS_XLINK_PREFIX "xlink:" 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #define ATTRIBUTE_XMLNS_EVENT "xmlns:event" 75*cdf0e10cSrcweir #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink" 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir #define XMLNS_FILTER_SEPARATOR "^" 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir #define ELEMENT_EVENTS "events" 80*cdf0e10cSrcweir #define ELEMENT_EVENT "event" 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir #define ATTRIBUTE_LANGUAGE "language" 83*cdf0e10cSrcweir #define ATTRIBUTE_LIBRARY "library" 84*cdf0e10cSrcweir #define ATTRIBUTE_NAME "name" 85*cdf0e10cSrcweir #define ATTRIBUTE_HREF "href" 86*cdf0e10cSrcweir #define ATTRIBUTE_TYPE "type" 87*cdf0e10cSrcweir #define ATTRIBUTE_MACRONAME "macro-name" 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir #define ELEMENT_NS_EVENTS "event:events" 90*cdf0e10cSrcweir #define ELEMENT_NS_EVENT "event:event" 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir #define ATTRIBUTE_TYPE_CDATA "CDATA" 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir #define EVENTS_DOCTYPE "<!DOCTYPE event:events PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"event.dtd\">" 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // Property names for events 97*cdf0e10cSrcweir #define PROP_EVENT_TYPE "EventType" 98*cdf0e10cSrcweir #define PROP_LIBRARY "Library" 99*cdf0e10cSrcweir #define PROP_SCRIPT "Script" 100*cdf0e10cSrcweir #define PROP_MACRO_NAME "MacroName" 101*cdf0e10cSrcweir #define STAR_BASIC "StarBasic" 102*cdf0e10cSrcweir #define JAVA_SCRIPT "JavaScript" 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir namespace framework 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir struct EventEntryProperty 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir OReadEventsDocumentHandler::Event_XML_Namespace nNamespace; 111*cdf0e10cSrcweir char aEntryName[20]; 112*cdf0e10cSrcweir }; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir static EventEntryProperty EventEntries[OReadEventsDocumentHandler::EV_XML_ENTRY_COUNT] = 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ELEMENT_EVENTS }, 117*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ELEMENT_EVENT }, 118*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ATTRIBUTE_LANGUAGE }, 119*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ATTRIBUTE_NAME }, 120*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_XLINK, ATTRIBUTE_HREF }, 121*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_XLINK, ATTRIBUTE_TYPE }, 122*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ATTRIBUTE_MACRONAME }, 123*cdf0e10cSrcweir { OReadEventsDocumentHandler::EV_NS_EVENT, ATTRIBUTE_LIBRARY } 124*cdf0e10cSrcweir }; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir OReadEventsDocumentHandler::OReadEventsDocumentHandler( EventsConfig& aItems ) : 128*cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 129*cdf0e10cSrcweir m_aEventItems( aItems ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir ::rtl::OUString aNamespaceEvent( RTL_CONSTASCII_USTRINGPARAM( XMLNS_EVENT )); 132*cdf0e10cSrcweir ::rtl::OUString aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )); 133*cdf0e10cSrcweir ::rtl::OUString aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR )); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // create hash map 136*cdf0e10cSrcweir for ( int i = 0; i < (int)EV_XML_ENTRY_COUNT; i++ ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir if ( EventEntries[i].nNamespace == EV_NS_EVENT ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir ::rtl::OUString temp( aNamespaceEvent ); 141*cdf0e10cSrcweir temp += aSeparator; 142*cdf0e10cSrcweir temp += ::rtl::OUString::createFromAscii( EventEntries[i].aEntryName ); 143*cdf0e10cSrcweir m_aEventsMap.insert( EventsHashMap::value_type( temp, (Events_XML_Entry)i ) ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir else 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir ::rtl::OUString temp( aNamespaceXLink ); 148*cdf0e10cSrcweir temp += aSeparator; 149*cdf0e10cSrcweir temp += ::rtl::OUString::createFromAscii( EventEntries[i].aEntryName ); 150*cdf0e10cSrcweir m_aEventsMap.insert( EventsHashMap::value_type( temp, (Events_XML_Entry)i ) ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir m_bEventsStartFound = sal_False; 155*cdf0e10cSrcweir m_bEventsEndFound = sal_False; 156*cdf0e10cSrcweir m_bEventStartFound = sal_False; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir OReadEventsDocumentHandler::~OReadEventsDocumentHandler() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // XDocumentHandler 164*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::startDocument(void) 165*cdf0e10cSrcweir throw ( SAXException, RuntimeException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::endDocument(void) 170*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if (( m_bEventsStartFound && !m_bEventsEndFound ) || 175*cdf0e10cSrcweir ( !m_bEventsStartFound && m_bEventsEndFound ) ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 178*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'event:events' found!" )); 179*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::startElement( 184*cdf0e10cSrcweir const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttribs ) 185*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir EventsHashMap::const_iterator pEventEntry = m_aEventsMap.find( aName ); 190*cdf0e10cSrcweir if ( pEventEntry != m_aEventsMap.end() ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir switch ( pEventEntry->second ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir case EV_ELEMENT_EVENTS: 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir if ( m_bEventsStartFound ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 199*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'event:events' cannot be embeded into 'event:events'!" )); 200*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir m_bEventsStartFound = sal_True; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir break; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir case EV_ELEMENT_EVENT: 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir if ( !m_bEventsStartFound ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 212*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'event:event' must be embeded into element 'event:events'!" )); 213*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if ( m_bEventStartFound ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 219*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element event:event is not a container!" )); 220*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir ::rtl::OUString aLanguage; 224*cdf0e10cSrcweir ::rtl::OUString aURL; 225*cdf0e10cSrcweir ::rtl::OUString aMacroName; 226*cdf0e10cSrcweir ::rtl::OUString aLibrary; 227*cdf0e10cSrcweir ::rtl::OUString aEventName; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir m_bEventStartFound = sal_True; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir long nIndex = m_aEventItems.aEventNames.getLength(); 232*cdf0e10cSrcweir long nPropCount = 2; // every event config entry needs at least 2 properties 233*cdf0e10cSrcweir Sequence< PropertyValue > aEventProperties( nPropCount ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir m_aEventItems.aEventNames.realloc( nIndex + 1 ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir pEventEntry = m_aEventsMap.find( xAttribs->getNameByIndex( n ) ); 240*cdf0e10cSrcweir if ( pEventEntry != m_aEventsMap.end() ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir switch ( pEventEntry->second ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir case EV_ATTRIBUTE_TYPE: 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir aLanguage = xAttribs->getValueByIndex( n ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir break; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir case EV_ATTRIBUTE_NAME: 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir aEventName = xAttribs->getValueByIndex( n ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir break; 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir case XL_ATTRIBUTE_HREF: 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir aURL = xAttribs->getValueByIndex( n ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir break; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir case EV_ATTRIBUTE_MACRONAME: 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir aMacroName = xAttribs->getValueByIndex( n ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir break; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir case EV_ATTRIBUTE_LIBRARY: 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir aLibrary = xAttribs->getValueByIndex( n ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir break; 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir default: 275*cdf0e10cSrcweir break; // nothing to do 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } // for 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir ::rtl::OUString aRequiredAttributeName; 281*cdf0e10cSrcweir if ( aLanguage.getLength() == 0 ) 282*cdf0e10cSrcweir aRequiredAttributeName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE )); 283*cdf0e10cSrcweir else if ( aEventName.getLength() == 0 ) 284*cdf0e10cSrcweir aRequiredAttributeName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NAME )); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // check for missing attribute values 287*cdf0e10cSrcweir if ( aRequiredAttributeName.getLength() > 0 ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 290*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute ")); 291*cdf0e10cSrcweir aErrorMessage += aRequiredAttributeName; 292*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " must have a value!" )); 293*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir Any a; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // set properties 299*cdf0e10cSrcweir a <<= aLanguage; 300*cdf0e10cSrcweir aEventProperties[0].Value <<= a; 301*cdf0e10cSrcweir aEventProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PROP_EVENT_TYPE )); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir a <<= aMacroName; 304*cdf0e10cSrcweir aEventProperties[1].Value <<= a; 305*cdf0e10cSrcweir aEventProperties[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PROP_MACRO_NAME )); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir if ( aLibrary.getLength() > 0 ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir ++nPropCount; 310*cdf0e10cSrcweir aEventProperties.realloc( nPropCount ); 311*cdf0e10cSrcweir a <<= aLibrary; 312*cdf0e10cSrcweir aEventProperties[nPropCount-1].Value <<= a; 313*cdf0e10cSrcweir aEventProperties[nPropCount-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PROP_LIBRARY )); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir if ( aURL.getLength() > 0 ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir ++nPropCount; 319*cdf0e10cSrcweir aEventProperties.realloc( nPropCount ); 320*cdf0e10cSrcweir a <<= aURL; 321*cdf0e10cSrcweir aEventProperties[nPropCount-1].Value <<= a; 322*cdf0e10cSrcweir aEventProperties[nPropCount-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PROP_SCRIPT )); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // set event name 326*cdf0e10cSrcweir m_aEventItems.aEventNames[ nIndex ] = aEventName; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir m_aEventItems.aEventsProperties.realloc( nIndex + 1 ); 329*cdf0e10cSrcweir a <<= aEventProperties; 330*cdf0e10cSrcweir m_aEventItems.aEventsProperties[ nIndex ] = a; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir break; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir default: 335*cdf0e10cSrcweir break; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::endElement(const ::rtl::OUString& aName) 341*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir EventsHashMap::const_iterator pEventEntry = m_aEventsMap.find( aName ); 346*cdf0e10cSrcweir if ( pEventEntry != m_aEventsMap.end() ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir switch ( pEventEntry->second ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir case EV_ELEMENT_EVENTS: 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir if ( !m_bEventsStartFound ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 355*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'event:events' found, but no start element" )); 356*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir m_bEventsStartFound = sal_False; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir break; 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir case EV_ELEMENT_EVENT: 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir if ( !m_bEventStartFound ) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 368*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'event:event' found, but no start element" )); 369*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir m_bEventStartFound = sal_False; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir break; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir default: 377*cdf0e10cSrcweir break; // impossible case 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::characters(const ::rtl::OUString&) 383*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::ignorableWhitespace(const ::rtl::OUString&) 388*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::processingInstruction( 393*cdf0e10cSrcweir const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ ) 394*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir void SAL_CALL OReadEventsDocumentHandler::setDocumentLocator( 399*cdf0e10cSrcweir const Reference< XLocator > &xLocator) 400*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir m_xLocator = xLocator; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir ::rtl::OUString OReadEventsDocumentHandler::getErrorLineString() 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir char buffer[32]; 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir if ( m_xLocator.is() ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>(m_xLocator->getLineNumber() )); 416*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( buffer ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir else 419*cdf0e10cSrcweir return ::rtl::OUString(); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 424*cdf0e10cSrcweir // OWriteEventsDocumentHandler 425*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir OWriteEventsDocumentHandler::OWriteEventsDocumentHandler( 428*cdf0e10cSrcweir const EventsConfig& aItems, 429*cdf0e10cSrcweir Reference< XDocumentHandler > rWriteDocumentHandler ) : 430*cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 431*cdf0e10cSrcweir m_aItems( aItems ), 432*cdf0e10cSrcweir m_xWriteDocumentHandler( rWriteDocumentHandler ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 435*cdf0e10cSrcweir m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY ); 436*cdf0e10cSrcweir m_aAttributeType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA )); 437*cdf0e10cSrcweir m_aXMLXlinkNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX )); 438*cdf0e10cSrcweir m_aXMLEventNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_EVENT_PREFIX )); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir OWriteEventsDocumentHandler::~OWriteEventsDocumentHandler() 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir void OWriteEventsDocumentHandler::WriteEventsDocument() throw 446*cdf0e10cSrcweir ( SAXException, RuntimeException ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir m_xWriteDocumentHandler->startDocument(); 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir // write DOCTYPE line! 453*cdf0e10cSrcweir Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY ); 454*cdf0e10cSrcweir if ( xExtendedDocHandler.is() ) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir xExtendedDocHandler->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( EVENTS_DOCTYPE )) ); 457*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 461*cdf0e10cSrcweir Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY ); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_EVENT )), 464*cdf0e10cSrcweir m_aAttributeType, 465*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_EVENT )) ); 466*cdf0e10cSrcweir pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK )), 467*cdf0e10cSrcweir m_aAttributeType, 468*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )) ); 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EVENTS )), pList ); 471*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir Sequence< PropertyValue > aEventProperties; 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir for ( int i = 0; i < m_aItems.aEventNames.getLength(); i++ ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir if ( m_aItems.aEventsProperties[i] >>= aEventProperties ) 478*cdf0e10cSrcweir WriteEvent( m_aItems.aEventNames[i], aEventProperties ); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 482*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EVENTS )) ); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 485*cdf0e10cSrcweir m_xWriteDocumentHandler->endDocument(); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 489*cdf0e10cSrcweir // protected member functions 490*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir void OWriteEventsDocumentHandler::WriteEvent( const ::rtl::OUString& aEventName, const Sequence< PropertyValue >& aPropertyValues ) throw 493*cdf0e10cSrcweir ( SAXException, RuntimeException ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir if ( aPropertyValues.getLength() > 0 ) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 498*cdf0e10cSrcweir Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY ); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir if ( m_aAttributeURL.getLength() == 0 ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir m_aAttributeURL = m_aXMLXlinkNS; 503*cdf0e10cSrcweir m_aAttributeURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HREF )); 504*cdf0e10cSrcweir m_aAttributeLinkType = m_aXMLXlinkNS; 505*cdf0e10cSrcweir m_aAttributeLinkType += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE )); 506*cdf0e10cSrcweir m_aAttributeLanguage = m_aXMLEventNS; 507*cdf0e10cSrcweir m_aAttributeLanguage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_LANGUAGE )); 508*cdf0e10cSrcweir m_aAttributeMacroName = m_aXMLEventNS; 509*cdf0e10cSrcweir m_aAttributeMacroName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MACRONAME )); 510*cdf0e10cSrcweir m_aAttributeLibrary = m_aXMLEventNS; 511*cdf0e10cSrcweir m_aAttributeLibrary += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_LIBRARY )); 512*cdf0e10cSrcweir m_aAttributeName = m_aXMLEventNS; 513*cdf0e10cSrcweir m_aAttributeName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NAME )); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeName, m_aAttributeType, aEventName ); 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir sal_Bool bURLSet = sal_False; 519*cdf0e10cSrcweir ::rtl::OUString aValue; 520*cdf0e10cSrcweir ::rtl::OUString aName; 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir // save attributes 523*cdf0e10cSrcweir for ( int i = 0; i < aPropertyValues.getLength(); i++ ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir aPropertyValues[i].Value >>= aValue; 526*cdf0e10cSrcweir if ( aPropertyValues[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( PROP_EVENT_TYPE ))) 527*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeLanguage, m_aAttributeType, aValue ); 528*cdf0e10cSrcweir else if ( aPropertyValues[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( PROP_MACRO_NAME )) && 529*cdf0e10cSrcweir aValue.getLength() > 0 ) 530*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeMacroName, m_aAttributeType, aValue ); 531*cdf0e10cSrcweir else if ( aPropertyValues[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( PROP_LIBRARY )) && 532*cdf0e10cSrcweir aValue.getLength() > 0 ) 533*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeLibrary, m_aAttributeType, aValue ); 534*cdf0e10cSrcweir else if ( aPropertyValues[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( PROP_SCRIPT ))) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeURL, m_aAttributeType, aValue ); 537*cdf0e10cSrcweir bURLSet = sal_True; 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir if ( bURLSet ) 542*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeLinkType, m_aAttributeType, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "simple" )) ); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EVENT )), xList ); 545*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_EVENT )) ); 548*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir } // namespace framework 553*cdf0e10cSrcweir 554