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>
23 #include <xml/menudocumenthandler.hxx>
24 #include <xml/saxnamespacefilter.hxx>
26 #include <uielement/rootitemcontainer.hxx>
28 #include <com/sun/star/xml/sax/Parser.hpp>
29 #include <com/sun/star/xml/sax/Writer.hpp>
30 #include <com/sun/star/xml/sax/SAXException.hpp>
31 #include <com/sun/star/io/IOException.hpp>
32 #include <cppuhelper/exc_hlp.hxx>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
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(
45 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
46 : m_xContext( rxContext
)
50 MenuConfiguration::~MenuConfiguration()
54 Reference
< XIndexAccess
> MenuConfiguration::CreateMenuBarConfigurationFromXML(
55 Reference
< XInputStream
> const & rInputStream
)
57 Reference
< XParser
> xParser
= Parser::create( m_xContext
);
59 // connect stream to input stream to the parser
60 InputSource aInputSource
;
62 aInputSource
.aInputStream
= rInputStream
;
65 Reference
< XIndexContainer
> xItemContainer( new RootItemContainer() );
67 // create namespace filter and set menudocument handler inside to support xml namespaces
69 Reference
< XDocumentHandler
> xDocHandler( new OReadMenuDocumentHandler( xItemContainer
));
71 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
73 // connect parser and filter
74 xParser
->setDocumentHandler( xFilter
);
78 xParser
->parseStream( aInputSource
);
79 return xItemContainer
;
81 catch ( const RuntimeException
& e
)
83 css::uno::Any anyEx
= cppu::getCaughtException();
84 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
86 catch( const SAXException
& e
)
88 css::uno::Any anyEx
= cppu::getCaughtException();
89 SAXException aWrappedSAXException
;
91 if ( !( e
.WrappedException
>>= aWrappedSAXException
))
92 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
94 throw WrappedTargetException( aWrappedSAXException
.Message
, Reference
< XInterface
>(), e
.WrappedException
);
96 catch( const css::io::IOException
& e
)
98 css::uno::Any anyEx
= cppu::getCaughtException();
99 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
103 void MenuConfiguration::StoreMenuBarConfigurationToXML(
104 Reference
< XIndexAccess
> const & rMenuBarConfiguration
,
105 Reference
< XOutputStream
> const & rOutputStream
, bool bIsMenuBar
)
107 Reference
< XWriter
> xWriter
= Writer::create(m_xContext
);
108 xWriter
->setOutputStream( rOutputStream
);
112 OWriteMenuDocumentHandler
aWriteMenuDocumentHandler( rMenuBarConfiguration
, xWriter
, bIsMenuBar
);
113 aWriteMenuDocumentHandler
.WriteMenuDocument();
115 catch ( const RuntimeException
& e
)
117 css::uno::Any anyEx
= cppu::getCaughtException();
118 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
120 catch ( const SAXException
& e
)
122 css::uno::Any anyEx
= cppu::getCaughtException();
123 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
125 catch ( const css::io::IOException
& e
)
127 css::uno::Any anyEx
= cppu::getCaughtException();
128 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), anyEx
);
132 void* MenuAttributes::CreateAttribute(const OUString
& rFrame
, const OUString
& rImageIdStr
)
134 MenuAttributes
* pAttributes
= new MenuAttributes(rFrame
, rImageIdStr
);
135 pAttributes
->acquire();
139 void* MenuAttributes::CreateAttribute(const css::uno::WeakReference
<css::frame::XDispatchProvider
>& rDispatchProvider
)
141 MenuAttributes
* pAttributes
= new MenuAttributes(rDispatchProvider
);
142 pAttributes
->acquire();
146 void MenuAttributes::ReleaseAttribute(void* nAttributePtr
)
150 MenuAttributes
* pAttributes
= static_cast<MenuAttributes
*>(nAttributePtr
);
151 pAttributes
->release();
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */