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 <framework/menuconfiguration.hxx>
22 #include <framework/addonmenu.hxx>
23 #include <xml/menudocumenthandler.hxx>
24 #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 <com/sun/star/io/XActiveDataSource.hpp>
34 #include <cppuhelper/exc_hlp.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::xml::sax
;
40 using namespace ::com::sun::star::container
;
41 using namespace ::com::sun::star::io
;
46 MenuConfiguration::MenuConfiguration(
47 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
48 : m_xContext( rxContext
)
52 MenuConfiguration::~MenuConfiguration()
56 Reference
< XIndexAccess
> MenuConfiguration::CreateMenuBarConfigurationFromXML(
57 Reference
< XInputStream
> const & rInputStream
)
59 Reference
< XParser
> xParser
= Parser::create( m_xContext
);
61 // connect stream to input stream to the parser
62 InputSource aInputSource
;
64 aInputSource
.aInputStream
= rInputStream
;
67 Reference
< XIndexContainer
> xItemContainer( static_cast< cppu::OWeakObject
*>( new RootItemContainer()), UNO_QUERY
);
69 // create namespace filter and set menudocument handler inside to support xml namespaces
71 Reference
< XDocumentHandler
> xDocHandler( new OReadMenuDocumentHandler( xItemContainer
));
73 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
75 // connect parser and filter
76 xParser
->setDocumentHandler( xFilter
);
80 xParser
->parseStream( aInputSource
);
81 return xItemContainer
;
83 catch ( const RuntimeException
& e
)
85 css::uno::Any anyEx
= cppu::getCaughtException();
86 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
88 catch( const SAXException
& e
)
90 css::uno::Any anyEx
= cppu::getCaughtException();
91 SAXException aWrappedSAXException
;
93 if ( !( e
.WrappedException
>>= aWrappedSAXException
))
94 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
96 throw WrappedTargetException( aWrappedSAXException
.Message
, Reference
< XInterface
>(), e
.WrappedException
);
98 catch( const css::io::IOException
& e
)
100 css::uno::Any anyEx
= cppu::getCaughtException();
101 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
105 void MenuConfiguration::StoreMenuBarConfigurationToXML(
106 Reference
< XIndexAccess
> const & rMenuBarConfiguration
,
107 Reference
< XOutputStream
> const & rOutputStream
, bool bIsMenuBar
)
109 Reference
< XWriter
> xWriter
= Writer::create(m_xContext
);
110 xWriter
->setOutputStream( rOutputStream
);
114 OWriteMenuDocumentHandler
aWriteMenuDocumentHandler( rMenuBarConfiguration
, xWriter
, bIsMenuBar
);
115 aWriteMenuDocumentHandler
.WriteMenuDocument();
117 catch ( const RuntimeException
& e
)
119 css::uno::Any anyEx
= cppu::getCaughtException();
120 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
122 catch ( const SAXException
& e
)
124 css::uno::Any anyEx
= cppu::getCaughtException();
125 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
127 catch ( const css::io::IOException
& e
)
129 css::uno::Any anyEx
= cppu::getCaughtException();
130 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
134 void* MenuAttributes::CreateAttribute(const OUString
& rFrame
, const OUString
& rImageIdStr
)
136 MenuAttributes
* pAttributes
= new MenuAttributes(rFrame
, rImageIdStr
);
137 pAttributes
->acquire();
141 void* MenuAttributes::CreateAttribute(const css::uno::WeakReference
<css::frame::XDispatchProvider
>& rDispatchProvider
)
143 MenuAttributes
* pAttributes
= new MenuAttributes(rDispatchProvider
);
144 pAttributes
->acquire();
148 void MenuAttributes::ReleaseAttribute(void* nAttributePtr
)
152 MenuAttributes
* pAttributes
= static_cast<MenuAttributes
*>(nAttributePtr
);
153 pAttributes
->release();
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */