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"
22 #include <comphelper/sequence.hxx>
23 #include <sal/log.hxx>
24 
25 namespace 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 );
58  if (sLibrary == EVENT_APPLICATION)
59  sLibrary = EVENT_STAROFFICE;
60 
61  sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
62  }
63  // tree property values to describe one event ...
64  rMappedEvent.realloc( sLibrary.isEmpty() ? 2 : 3 );
65 
66  // ... the type
67  rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(rEvent.ScriptType), PropertyState_DIRECT_VALUE);
68 
69  // and the macro name
70  rMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, makeAny(sLocalMacroName), PropertyState_DIRECT_VALUE);
71 
72  // the library
73  if ( !sLibrary.isEmpty() )
74  rMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, makeAny(sLibrary), PropertyState_DIRECT_VALUE);
75  }
76  else
77  {
78  rMappedEvent.realloc( 2 );
79  rMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, makeAny(rEvent.ScriptType), PropertyState_DIRECT_VALUE);
80  // and the macro name
81  rMappedEvent[1] = PropertyValue(EVENT_SCRIPTURL, -1, makeAny(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.", static_cast< ::cppu::OWeakObject* >(this), 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  static_cast< ::cppu::OWeakObject* >(this));
99 
100  return makeAny(aPos->second);
101  }
102 
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: */
Type
#define EVENT_SCRIPTURL
Definition: strings.hxx:201
virtual sal_Bool SAL_CALL hasElements() override
MapString2PropertyValueSequence m_aMappedEvents
Definition: eventexport.hxx:51
#define EVENT_NAME_SEPARATOR
Definition: strings.hxx:197
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: eventexport.cxx:92
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
#define EVENT_APPLICATION
Definition: strings.hxx:204
const char sLibrary[]
const char * sName
virtual css::uno::Type SAL_CALL getElementType() override
OEventDescriptorMapper(const css::uno::Sequence< css::script::ScriptEventDescriptor > &_rEvents)
Definition: eventexport.cxx:35
#define EVENT_STAROFFICE
Definition: strings.hxx:202
#define EVENT_LOCALMACRONAME
Definition: strings.hxx:200
unsigned char sal_Bool
#define EVENT_LIBRARY
Definition: strings.hxx:199
#define EVENT_STARBASIC
Definition: strings.hxx:203
#define SAL_WARN_IF(condition, area, stream)
#define EVENT_TYPE
Definition: strings.hxx:198
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: eventexport.cxx:86
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)