LibreOffice Module framework (master) 1
menuconfiguration.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 <menuconfiguration.hxx>
21
22#include <addonmenu.hxx>
23#include <utility>
26
28
29#include <com/sun/star/xml/sax/Parser.hpp>
30#include <com/sun/star/xml/sax/Writer.hpp>
31#include <com/sun/star/xml/sax/SAXException.hpp>
32#include <com/sun/star/io/IOException.hpp>
34
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::xml::sax;
39using namespace ::com::sun::star::container;
40using namespace ::com::sun::star::io;
41
42namespace framework
43{
44
45MenuConfiguration::MenuConfiguration( css::uno::Reference< css::uno::XComponentContext > xContext )
46: m_xContext(std::move( xContext ))
47{
48}
49
51{
52}
53
55 Reference< XInputStream > const & rInputStream )
56{
57 Reference< XParser > xParser = Parser::create( m_xContext );
58
59 // connect stream to input stream to the parser
60 InputSource aInputSource;
61
62 aInputSource.aInputStream = rInputStream;
63
64 // create menu bar
65 Reference< XIndexContainer > xItemContainer( new RootItemContainer() );
66
67 // create namespace filter and set menudocument handler inside to support xml namespaces
68
69 Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
70
71 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
72
73 // connect parser and filter
74 xParser->setDocumentHandler( xFilter );
75
76 try
77 {
78 xParser->parseStream( aInputSource );
79 return xItemContainer;
80 }
81 catch ( const RuntimeException& e )
82 {
83 css::uno::Any anyEx = cppu::getCaughtException();
84 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
85 }
86 catch( const SAXException& e )
87 {
88 css::uno::Any anyEx = cppu::getCaughtException();
89 SAXException aWrappedSAXException;
90
91 if ( !( e.WrappedException >>= aWrappedSAXException ))
92 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
93 else
94 throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), e.WrappedException );
95 }
96 catch( const css::io::IOException& e )
97 {
98 css::uno::Any anyEx = cppu::getCaughtException();
99 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
100 }
101}
102
104 Reference< XIndexAccess > const & rMenuBarConfiguration,
105 Reference< XOutputStream > const & rOutputStream, bool bIsMenuBar )
106{
107 Reference< XWriter > xWriter = Writer::create(m_xContext);
108 xWriter->setOutputStream( rOutputStream );
109
110 try
111 {
112 OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter, bIsMenuBar );
113 aWriteMenuDocumentHandler.WriteMenuDocument();
114 }
115 catch ( const RuntimeException& e )
116 {
117 css::uno::Any anyEx = cppu::getCaughtException();
118 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
119 }
120 catch ( const SAXException& e )
121 {
122 css::uno::Any anyEx = cppu::getCaughtException();
123 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
124 }
125 catch ( const css::io::IOException& e )
126 {
127 css::uno::Any anyEx = cppu::getCaughtException();
128 throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx );
129 }
130}
131
132void* MenuAttributes::CreateAttribute(const OUString& rFrame, const OUString& rImageIdStr)
133{
134 MenuAttributes* pAttributes = new MenuAttributes(rFrame, rImageIdStr);
135 pAttributes->acquire();
136 return pAttributes;
137}
138
139void* MenuAttributes::CreateAttribute(const css::uno::WeakReference<css::frame::XDispatchProvider>& rDispatchProvider)
140{
141 MenuAttributes* pAttributes = new MenuAttributes(rDispatchProvider);
142 pAttributes->acquire();
143 return pAttributes;
144}
145
146void MenuAttributes::ReleaseAttribute(void* nAttributePtr)
147{
148 if (!nAttributePtr)
149 return;
150 MenuAttributes* pAttributes = static_cast<MenuAttributes*>(nAttributePtr);
151 pAttributes->release();
152}
153
154}
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void StoreMenuBarConfigurationToXML(css::uno::Reference< css::container::XIndexAccess > const &rMenuBarConfiguration, css::uno::Reference< css::io::XOutputStream > const &rOutputStream, bool bIsMenuBar)
MenuConfiguration(css::uno::Reference< css::uno::XComponentContext > rxContext)
css::uno::Reference< css::container::XIndexAccess > CreateMenuBarConfigurationFromXML(css::uno::Reference< css::io::XInputStream > const &rInputStream)
css::uno::Reference< css::uno::XComponentContext > m_xContext
Reference< XInputStream > rInputStream
css::uno::Reference< css::uno::XComponentContext > m_xContext
Any SAL_CALL getCaughtException()
MenuAttributes(OUString sFrame, OUString sImageIdStr)
static void ReleaseAttribute(void *nAttributePtr)
static void * CreateAttribute(const OUString &rFrame, const OUString &rImageIdStr)