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