LibreOffice Module xmloff (master) 1
eventexport.cxx
Go to the documentation of this file.
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 "strings.hxx"
23#include <sal/log.hxx>
24
25namespace xmloff
26{
27
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::script;
30 using namespace ::com::sun::star::container;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::lang;
33
34 //= OEventDescriptorMapper
35 OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents)
36 {
37 // translate the events
38 OUString sLibrary, sLocalMacroName;
39 for (const auto& rEvent : _rEvents)
40 {
41 // the name of the event is build from listener interface and listener method name
42 OUString sName = rEvent.ListenerType
44 + rEvent.EventMethod;
45
46 Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName];
47
48 sLocalMacroName = rEvent.ScriptCode;
49 sLibrary.clear();
50 if (rEvent.ScriptType == EVENT_STARBASIC)
51 { // for StarBasic, the library name is part of the ScriptCode
52 sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' );
53 SAL_WARN_IF( 0 > nPrefixLen, "xmloff", "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
54 if ( 0 <= nPrefixLen )
55 {
56 // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
57 sLibrary = sLocalMacroName.copy( 0, nPrefixLen );
60
61 sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
62 }
63 // tree property values to describe one event ...
64 rMappedEvent.realloc( sLibrary.isEmpty() ? 2 : 3 );
65 auto pMappedEvent = rMappedEvent.getArray();
66
67 // ... the type
68 pMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, Any(rEvent.ScriptType), PropertyState_DIRECT_VALUE);
69
70 // and the macro name
71 pMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, Any(sLocalMacroName), PropertyState_DIRECT_VALUE);
72
73 // the library
74 if ( !sLibrary.isEmpty() )
75 pMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, Any(sLibrary), PropertyState_DIRECT_VALUE);
76 }
77 else
78 {
79 rMappedEvent = { PropertyValue(EVENT_TYPE, -1, Any(rEvent.ScriptType), PropertyState_DIRECT_VALUE),
80 // and the macro name
81 PropertyValue(EVENT_SCRIPTURL, -1, Any(rEvent.ScriptCode), PropertyState_DIRECT_VALUE) };
82 }
83 }
84 }
85
86 void SAL_CALL OEventDescriptorMapper::replaceByName( const OUString&, const Any& )
87 {
88 throw IllegalArgumentException(
89 "replacing is not implemented for this wrapper class.", getXWeak(), 1);
90 }
91
92 Any SAL_CALL OEventDescriptorMapper::getByName( const OUString& _rName )
93 {
94 MapString2PropertyValueSequence::const_iterator aPos = m_aMappedEvents.find(_rName);
95 if (m_aMappedEvents.end() == aPos)
96 throw NoSuchElementException(
97 "There is no element named " + _rName,
98 getXWeak());
99
100 return Any(aPos->second);
101 }
102
103 Sequence< OUString > SAL_CALL OEventDescriptorMapper::getElementNames( )
104 {
106 }
107
108 sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const OUString& _rName )
109 {
110 MapString2PropertyValueSequence::const_iterator aPos = m_aMappedEvents.find(_rName);
111 return m_aMappedEvents.end() != aPos;
112 }
113
115 {
116 return ::cppu::UnoType<PropertyValue>::get();
117 }
118
120 {
121 return !m_aMappedEvents.empty();
122 }
123
124} // namespace xmloff
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
OEventDescriptorMapper(const css::uno::Sequence< css::script::ScriptEventDescriptor > &_rEvents)
Definition: eventexport.cxx:35
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
MapString2PropertyValueSequence m_aMappedEvents
Definition: eventexport.hxx:50
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: eventexport.cxx:92
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: eventexport.cxx:86
OUString sName
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
Type
constexpr OUStringLiteral EVENT_APPLICATION
Definition: strings.hxx:204
constexpr OUStringLiteral EVENT_LIBRARY
Definition: strings.hxx:199
constexpr OUStringLiteral EVENT_TYPE
Definition: strings.hxx:198
constexpr OUStringLiteral EVENT_SCRIPTURL
Definition: strings.hxx:201
constexpr OUStringLiteral EVENT_STAROFFICE
Definition: strings.hxx:202
constexpr OUStringLiteral EVENT_LOCALMACRONAME
Definition: strings.hxx:200
#define EVENT_STARBASIC
Definition: strings.hxx:203
#define EVENT_NAME_SEPARATOR
Definition: strings.hxx:197
unsigned char sal_Bool
constexpr OUStringLiteral sLibrary