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 "eventexport.hxx"
21 : #include <osl/diagnose.h>
22 : #include "strings.hxx"
23 : #include <tools/debug.hxx>
24 :
25 : //.........................................................................
26 : namespace xmloff
27 : {
28 : //.........................................................................
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::script;
32 : using namespace ::com::sun::star::container;
33 : using namespace ::com::sun::star::beans;
34 : using namespace ::com::sun::star::lang;
35 :
36 : //=====================================================================
37 : //= OEventDescriptorMapper
38 : //=====================================================================
39 : //---------------------------------------------------------------------
40 0 : OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents)
41 : {
42 0 : sal_Int32 nEvents = _rEvents.getLength();
43 :
44 : // translate the events
45 0 : const ScriptEventDescriptor* pEvents = _rEvents.getConstArray();
46 0 : ::rtl::OUString sName;
47 0 : ::rtl::OUString sLibrary, sLocalMacroName;
48 0 : for (sal_Int32 i=0; i<nEvents; ++i, ++pEvents)
49 : {
50 : // the name of the event is build from listener interface and listener method name
51 0 : sName = pEvents->ListenerType;
52 0 : sName += EVENT_NAME_SEPARATOR;
53 0 : sName += pEvents->EventMethod;
54 :
55 0 : Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName];
56 :
57 0 : sLocalMacroName = pEvents->ScriptCode;
58 0 : sLibrary = ::rtl::OUString();
59 0 : if (pEvents->ScriptType.equalsAsciiL(EVENT_STARBASIC.ascii, EVENT_STARBASIC.length))
60 : { // for StarBasic, the library name is part of the ScriptCode
61 0 : sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' );
62 : DBG_ASSERT( 0 <= nPrefixLen, "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
63 0 : if ( 0 <= nPrefixLen )
64 : {
65 : // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
66 0 : sLibrary = sLocalMacroName.copy( 0, nPrefixLen );
67 0 : if (sLibrary.equalsAsciiL(EVENT_APPLICATION.ascii, EVENT_APPLICATION.length))
68 0 : sLibrary = EVENT_STAROFFICE;
69 :
70 0 : sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
71 : }
72 : // tree property values to describe one event ...
73 0 : rMappedEvent.realloc( sLibrary.isEmpty() ? 2 : 3 );
74 :
75 : // ... the type
76 0 : rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
77 :
78 : // and the macro name
79 0 : rMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, makeAny(sLocalMacroName), PropertyState_DIRECT_VALUE);
80 :
81 : // the library
82 0 : if ( !sLibrary.isEmpty() )
83 0 : rMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, makeAny(sLibrary), PropertyState_DIRECT_VALUE);
84 : }
85 : else
86 : {
87 0 : rMappedEvent.realloc( 2 );
88 0 : rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(pEvents->ScriptType), PropertyState_DIRECT_VALUE);
89 : // and the macro name
90 0 : rMappedEvent[1] = PropertyValue(EVENT_SCRIPTURL, -1, makeAny(pEvents->ScriptCode), PropertyState_DIRECT_VALUE);
91 : }
92 0 : }
93 0 : }
94 :
95 : //---------------------------------------------------------------------
96 0 : void SAL_CALL OEventDescriptorMapper::replaceByName( const ::rtl::OUString&, const Any& ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
97 : {
98 : throw IllegalArgumentException(
99 0 : ::rtl::OUString("replacing is not implemented for this wrapper class."), static_cast< ::cppu::OWeakObject* >(this), 1);
100 : }
101 :
102 : //---------------------------------------------------------------------
103 0 : Any SAL_CALL OEventDescriptorMapper::getByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
104 : {
105 0 : ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
106 0 : if (m_aMappedEvents.end() == aPos)
107 : throw NoSuchElementException(
108 0 : ::rtl::OUString("There is no element named ") += _rName,
109 0 : static_cast< ::cppu::OWeakObject* >(this));
110 :
111 0 : return makeAny(aPos->second);
112 : }
113 :
114 : //---------------------------------------------------------------------
115 0 : Sequence< ::rtl::OUString > SAL_CALL OEventDescriptorMapper::getElementNames( ) throw(RuntimeException)
116 : {
117 0 : Sequence< ::rtl::OUString > aReturn(m_aMappedEvents.size());
118 0 : ::rtl::OUString* pReturn = aReturn.getArray();
119 0 : for ( ConstMapString2PropertyValueSequenceIterator aCollect = m_aMappedEvents.begin();
120 0 : aCollect != m_aMappedEvents.end();
121 : ++aCollect, ++pReturn
122 : )
123 0 : *pReturn = aCollect->first;
124 :
125 0 : return aReturn;
126 : }
127 :
128 : //---------------------------------------------------------------------
129 0 : sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
130 : {
131 0 : ConstMapString2PropertyValueSequenceIterator aPos = m_aMappedEvents.find(_rName);
132 0 : return m_aMappedEvents.end() != aPos;
133 : }
134 :
135 : //---------------------------------------------------------------------
136 0 : Type SAL_CALL OEventDescriptorMapper::getElementType( ) throw(RuntimeException)
137 : {
138 0 : return ::getCppuType(static_cast< PropertyValue* >(NULL));
139 : }
140 :
141 : //---------------------------------------------------------------------
142 0 : sal_Bool SAL_CALL OEventDescriptorMapper::hasElements( ) throw(RuntimeException)
143 : {
144 0 : return !m_aMappedEvents.empty();
145 : }
146 :
147 : //.........................................................................
148 : } // namespace xmloff
149 : //.........................................................................
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|