1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <menuconfiguration.hxx>
22 #include <addonmenu.hxx>
24 #include <xml/menudocumenthandler.hxx>
25 #include <xml/saxnamespacefilter.hxx>
27 #include <uielement/rootitemcontainer.hxx>
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>
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
;
44 MenuConfiguration::MenuConfiguration( css::uno::Reference
< css::uno::XComponentContext
> xContext
)
45 : m_xContext(std::move( xContext
))
49 MenuConfiguration::~MenuConfiguration()
53 Reference
< XIndexAccess
> MenuConfiguration::CreateMenuBarConfigurationFromXML(
54 Reference
< XInputStream
> const & rInputStream
)
56 Reference
< XParser
> xParser
= Parser::create( m_xContext
);
58 // connect stream to input stream to the parser
59 InputSource aInputSource
;
61 aInputSource
.aInputStream
= rInputStream
;
64 Reference
< XIndexContainer
> xItemContainer( new RootItemContainer() );
66 // create namespace filter and set menudocument handler inside to support xml namespaces
68 Reference
< XDocumentHandler
> xDocHandler( new OReadMenuDocumentHandler( xItemContainer
));
70 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
72 // connect parser and filter
73 xParser
->setDocumentHandler( xFilter
);
77 xParser
->parseStream( aInputSource
);
78 return xItemContainer
;
80 catch ( const RuntimeException
& e
)
82 css::uno::Any anyEx
= cppu::getCaughtException();
83 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
85 catch( const SAXException
& e
)
87 css::uno::Any anyEx
= cppu::getCaughtException();
88 SAXException aWrappedSAXException
;
90 if ( !( e
.WrappedException
>>= aWrappedSAXException
))
91 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
93 throw WrappedTargetException( aWrappedSAXException
.Message
, Reference
< XInterface
>(), e
.WrappedException
);
95 catch( const css::io::IOException
& e
)
97 css::uno::Any anyEx
= cppu::getCaughtException();
98 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
102 void MenuConfiguration::StoreMenuBarConfigurationToXML(
103 Reference
< XIndexAccess
> const & rMenuBarConfiguration
,
104 Reference
< XOutputStream
> const & rOutputStream
, bool bIsMenuBar
)
106 Reference
< XWriter
> xWriter
= Writer::create(m_xContext
);
107 xWriter
->setOutputStream( rOutputStream
);
111 OWriteMenuDocumentHandler
aWriteMenuDocumentHandler( rMenuBarConfiguration
, xWriter
, bIsMenuBar
);
112 aWriteMenuDocumentHandler
.WriteMenuDocument();
114 catch ( const RuntimeException
& e
)
116 css::uno::Any anyEx
= cppu::getCaughtException();
117 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
119 catch ( const SAXException
& e
)
121 css::uno::Any anyEx
= cppu::getCaughtException();
122 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
124 catch ( const css::io::IOException
& e
)
126 css::uno::Any anyEx
= cppu::getCaughtException();
127 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
131 void* MenuAttributes::CreateAttribute(const OUString
& rFrame
, const OUString
& rImageIdStr
)
133 MenuAttributes
* pAttributes
= new MenuAttributes(rFrame
, rImageIdStr
);
134 pAttributes
->acquire();
138 void* MenuAttributes::CreateAttribute(const css::uno::WeakReference
<css::frame::XDispatchProvider
>& rDispatchProvider
)
140 MenuAttributes
* pAttributes
= new MenuAttributes(rDispatchProvider
);
141 pAttributes
->acquire();
145 void MenuAttributes::ReleaseAttribute(void* nAttributePtr
)
149 MenuAttributes
* pAttributes
= static_cast<MenuAttributes
*>(nAttributePtr
);
150 pAttributes
->release();
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */