1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include "eventexport.hxx" 27 #include <osl/diagnose.h> 28 #include "strings.hxx" 29 #include <tools/debug.hxx> 30 31 //......................................................................... 32 namespace xmloff 33 { 34 //......................................................................... 35 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::script; 38 using namespace ::com::sun::star::container; 39 using namespace ::com::sun::star::beans; 40 using namespace ::com::sun::star::lang; 41 42 //===================================================================== 43 //= OEventDescriptorMapper 44 //===================================================================== 45 //--------------------------------------------------------------------- OEventDescriptorMapper(const Sequence<ScriptEventDescriptor> & _rEvents)46 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents) 47 { 48 sal_Int32 nEvents = _rEvents.getLength(); 49 50 // translate the events 51 const ScriptEventDescriptor* pEvents = _rEvents.getConstArray(); 52 ::rtl::OUString sName; 53 ::rtl::OUString sLibrary, sLocalMacroName; 54 for (sal_Int32 i=0; i<nEvents; ++i, ++pEvents) 55 { 56 // the name of the event is build from listener interface and listener method name 57 sName = pEvents->ListenerType; 58 sName += EVENT_NAME_SEPARATOR; 59 sName += pEvents->EventMethod; 60 61 Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName]; 62 63 sLocalMacroName = pEvents->ScriptCode; 64 sLibrary = ::rtl::OUString(); 65 if ( 0 == pEvents->ScriptType.compareToAscii( EVENT_STARBASIC ) ) 66 { // for StarBasic, the library name is part of the ScriptCode 67 sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' ); 68 DBG_ASSERT( 0 <= nPrefixLen, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" ); 69 if ( 0 <= nPrefixLen ) 70 { 71 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ... 72 sLibrary = sLocalMacroName.copy( 0, nPrefixLen ); 73 if ( sLibrary.equalsAscii( EVENT_APPLICATION ) ) 74 sLibrary = EVENT_STAROFFICE; 75 76 sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 ); 77 } 78 // tree property values to describe one event ... 79 rMappedEvent.realloc( sLibrary.getLength() ? 3 : 2 ); 80 81 // ... the type 82 rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE); 83 84 // and the macro name 85 rMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, makeAny(sLocalMacroName), PropertyState_DIRECT_VALUE); 86 87 // the library 88 if ( sLibrary.getLength() ) 89 rMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, makeAny(sLibrary), PropertyState_DIRECT_VALUE); 90 } 91 else 92 { 93 rMappedEvent.realloc( 2 ); 94 rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE); 95 // and the macro name 96 rMappedEvent[1] = PropertyValue(EVENT_SCRIPTURL, -1, makeAny(pEvents->ScriptCode), PropertyState_DIRECT_VALUE); 97 } 98 } 99 } 100 101 //--------------------------------------------------------------------- replaceByName(const::rtl::OUString &,const Any &)102 void SAL_CALL OEventDescriptorMapper::replaceByName( const ::rtl::OUString&, const Any& ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) 103 { 104 throw IllegalArgumentException( 105 ::rtl::OUString::createFromAscii("replacing is not implemented for this wrapper class."), static_cast< ::cppu::OWeakObject* >(this), 1); 106 } 107 108 //--------------------------------------------------------------------- getByName(const::rtl::OUString & _rName)109 Any SAL_CALL OEventDescriptorMapper::getByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) 110 { 111 ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName); 112 if (m_aMappedEvents.end() == aPos) 113 throw NoSuchElementException( 114 ::rtl::OUString::createFromAscii("There is no element named ") += _rName, 115 static_cast< ::cppu::OWeakObject* >(this)); 116 117 return makeAny(aPos->second); 118 } 119 120 //--------------------------------------------------------------------- getElementNames()121 Sequence< ::rtl::OUString > SAL_CALL OEventDescriptorMapper::getElementNames( ) throw(RuntimeException) 122 { 123 Sequence< ::rtl::OUString > aReturn(m_aMappedEvents.size()); 124 ::rtl::OUString* pReturn = aReturn.getArray(); 125 for ( ConstMapString2PropertyValueSequenceIterator aCollect = m_aMappedEvents.begin(); 126 aCollect != m_aMappedEvents.end(); 127 ++aCollect, ++pReturn 128 ) 129 *pReturn = aCollect->first; 130 131 return aReturn; 132 } 133 134 //--------------------------------------------------------------------- hasByName(const::rtl::OUString & _rName)135 sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const ::rtl::OUString& _rName ) throw(RuntimeException) 136 { 137 ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName); 138 return m_aMappedEvents.end() != aPos; 139 } 140 141 //--------------------------------------------------------------------- getElementType()142 Type SAL_CALL OEventDescriptorMapper::getElementType( ) throw(RuntimeException) 143 { 144 return ::getCppuType(static_cast< PropertyValue* >(NULL)); 145 } 146 147 //--------------------------------------------------------------------- hasElements()148 sal_Bool SAL_CALL OEventDescriptorMapper::hasElements( ) throw(RuntimeException) 149 { 150 return !m_aMappedEvents.empty(); 151 } 152 153 //......................................................................... 154 } // namespace xmloff 155 //......................................................................... 156 157