Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "eventexport.hxx"
30 : : #include <osl/diagnose.h>
31 : : #include "strings.hxx"
32 : : #include <tools/debug.hxx>
33 : :
34 : : //.........................................................................
35 : : namespace xmloff
36 : : {
37 : : //.........................................................................
38 : :
39 : : using namespace ::com::sun::star::uno;
40 : : using namespace ::com::sun::star::script;
41 : : using namespace ::com::sun::star::container;
42 : : using namespace ::com::sun::star::beans;
43 : : using namespace ::com::sun::star::lang;
44 : :
45 : : //=====================================================================
46 : : //= OEventDescriptorMapper
47 : : //=====================================================================
48 : : //---------------------------------------------------------------------
49 [ # # ]: 0 : OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents)
50 : : {
51 : 0 : sal_Int32 nEvents = _rEvents.getLength();
52 : :
53 : : // translate the events
54 : 0 : const ScriptEventDescriptor* pEvents = _rEvents.getConstArray();
55 : 0 : ::rtl::OUString sName;
56 : 0 : ::rtl::OUString sLibrary, sLocalMacroName;
57 [ # # ]: 0 : for (sal_Int32 i=0; i<nEvents; ++i, ++pEvents)
58 : : {
59 : : // the name of the event is build from listener interface and listener method name
60 : 0 : sName = pEvents->ListenerType;
61 [ # # ]: 0 : sName += EVENT_NAME_SEPARATOR;
62 : 0 : sName += pEvents->EventMethod;
63 : :
64 [ # # ]: 0 : Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName];
65 : :
66 : 0 : sLocalMacroName = pEvents->ScriptCode;
67 : 0 : sLibrary = ::rtl::OUString();
68 [ # # ]: 0 : if (pEvents->ScriptType.equalsAsciiL(EVENT_STARBASIC.ascii, EVENT_STARBASIC.length))
69 : : { // for StarBasic, the library name is part of the ScriptCode
70 : 0 : sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' );
71 : : DBG_ASSERT( 0 <= nPrefixLen, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
72 [ # # ]: 0 : if ( 0 <= nPrefixLen )
73 : : {
74 : : // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
75 : 0 : sLibrary = sLocalMacroName.copy( 0, nPrefixLen );
76 [ # # ]: 0 : if (sLibrary.equalsAsciiL(EVENT_APPLICATION.ascii, EVENT_APPLICATION.length))
77 [ # # ]: 0 : sLibrary = EVENT_STAROFFICE;
78 : :
79 : 0 : sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
80 : : }
81 : : // tree property values to describe one event ...
82 [ # # ][ # # ]: 0 : rMappedEvent.realloc( sLibrary.isEmpty() ? 2 : 3 );
83 : :
84 : : // ... the type
85 [ # # ][ # # ]: 0 : rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
[ # # ]
86 : :
87 : : // and the macro name
88 [ # # ][ # # ]: 0 : rMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, makeAny(sLocalMacroName), PropertyState_DIRECT_VALUE);
[ # # ]
89 : :
90 : : // the library
91 [ # # ]: 0 : if ( !sLibrary.isEmpty() )
92 [ # # ][ # # ]: 0 : rMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, makeAny(sLibrary), PropertyState_DIRECT_VALUE);
[ # # ]
93 : : }
94 : : else
95 : : {
96 [ # # ]: 0 : rMappedEvent.realloc( 2 );
97 [ # # ][ # # ]: 0 : rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
[ # # ]
98 : : // and the macro name
99 [ # # ][ # # ]: 0 : rMappedEvent[1] = PropertyValue(EVENT_SCRIPTURL, -1, makeAny(pEvents->ScriptCode), PropertyState_DIRECT_VALUE);
[ # # ]
100 : : }
101 : 0 : }
102 : 0 : }
103 : :
104 : : //---------------------------------------------------------------------
105 : 0 : void SAL_CALL OEventDescriptorMapper::replaceByName( const ::rtl::OUString&, const Any& ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
106 : : {
107 : : throw IllegalArgumentException(
108 [ # # ][ # # ]: 0 : ::rtl::OUString("replacing is not implemented for this wrapper class."), static_cast< ::cppu::OWeakObject* >(this), 1);
109 : : }
110 : :
111 : : //---------------------------------------------------------------------
112 : 0 : Any SAL_CALL OEventDescriptorMapper::getByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
113 : : {
114 [ # # ]: 0 : ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
115 [ # # ]: 0 : if (m_aMappedEvents.end() == aPos)
116 : : throw NoSuchElementException(
117 : 0 : ::rtl::OUString("There is no element named ") += _rName,
118 [ # # # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
119 : :
120 [ # # ]: 0 : return makeAny(aPos->second);
121 : : }
122 : :
123 : : //---------------------------------------------------------------------
124 : 0 : Sequence< ::rtl::OUString > SAL_CALL OEventDescriptorMapper::getElementNames( ) throw(RuntimeException)
125 : : {
126 : 0 : Sequence< ::rtl::OUString > aReturn(m_aMappedEvents.size());
127 [ # # ]: 0 : ::rtl::OUString* pReturn = aReturn.getArray();
128 [ # # ]: 0 : for ( ConstMapString2PropertyValueSequenceIterator aCollect = m_aMappedEvents.begin();
129 : 0 : aCollect != m_aMappedEvents.end();
130 : : ++aCollect, ++pReturn
131 : : )
132 : 0 : *pReturn = aCollect->first;
133 : :
134 : 0 : return aReturn;
135 : : }
136 : :
137 : : //---------------------------------------------------------------------
138 : 0 : sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
139 : : {
140 [ # # ]: 0 : ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
141 : 0 : return m_aMappedEvents.end() != aPos;
142 : : }
143 : :
144 : : //---------------------------------------------------------------------
145 : 0 : Type SAL_CALL OEventDescriptorMapper::getElementType( ) throw(RuntimeException)
146 : : {
147 : 0 : return ::getCppuType(static_cast< PropertyValue* >(NULL));
148 : : }
149 : :
150 : : //---------------------------------------------------------------------
151 : 0 : sal_Bool SAL_CALL OEventDescriptorMapper::hasElements( ) throw(RuntimeException)
152 : : {
153 : 0 : return !m_aMappedEvents.empty();
154 : : }
155 : :
156 : : //.........................................................................
157 : : } // namespace xmloff
158 : : //.........................................................................
159 : :
160 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|