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