xref: /AOO41X/main/framework/source/fwe/xml/menuconfiguration.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32*cdf0e10cSrcweir //	my own includes
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_BMKMENU_HXX_
37*cdf0e10cSrcweir #include <framework/bmkmenu.hxx>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <framework/addonmenu.hxx>
40*cdf0e10cSrcweir #include <xml/menudocumenthandler.hxx>
41*cdf0e10cSrcweir #include <xml/saxnamespacefilter.hxx>
42*cdf0e10cSrcweir #include <services.h>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #ifndef _FRAMEWORK_UIELEMENT_ROOTITEMCONTAINER_HXX_
45*cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
46*cdf0e10cSrcweir #endif
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49*cdf0e10cSrcweir //	interface includes
50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
56*cdf0e10cSrcweir //	namespace
57*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
60*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
61*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
62*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
63*cdf0e10cSrcweir using namespace ::com::sun::star::container;
64*cdf0e10cSrcweir using namespace ::com::sun::star::io;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace framework
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir sal_Bool MenuConfiguration::IsPickListItemId( sal_uInt16 nId )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     return (( START_ITEMID_PICKLIST <= nId ) && ( nId <= END_ITEMID_PICKLIST ));
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir sal_Bool MenuConfiguration::IsWindowListItemId( sal_uInt16 nId )
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     return (( START_ITEMID_WINDOWLIST <= nId ) && ( nId <= END_ITEMID_WINDOWLIST ));
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir MenuConfiguration::MenuConfiguration(
81*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager )
82*cdf0e10cSrcweir :	m_rxServiceManager( rServiceManager )
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir MenuConfiguration::~MenuConfiguration()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML(
93*cdf0e10cSrcweir     Reference< XInputStream >& rInputStream )
94*cdf0e10cSrcweir throw ( WrappedTargetException )
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir 	Reference< XParser > xParser( m_rxServiceManager->createInstance(SERVICENAME_SAXPARSER),UNO_QUERY);
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	// connect stream to input stream to the parser
99*cdf0e10cSrcweir 	InputSource aInputSource;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	aInputSource.aInputStream = rInputStream;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	// create menu bar
105*cdf0e10cSrcweir     Reference< XIndexContainer > xItemContainer( static_cast< cppu::OWeakObject *>( new RootItemContainer()), UNO_QUERY );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	// create namespace filter and set menudocument handler inside to support xml namespaces
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	// #110897# Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
110*cdf0e10cSrcweir 	Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( m_rxServiceManager, xItemContainer ));
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	// connect parser and filter
115*cdf0e10cSrcweir 	xParser->setDocumentHandler( xFilter );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	try
118*cdf0e10cSrcweir 	{
119*cdf0e10cSrcweir 		xParser->parseStream( aInputSource );
120*cdf0e10cSrcweir 		return Reference< XIndexAccess >( xItemContainer, UNO_QUERY );
121*cdf0e10cSrcweir 	}
122*cdf0e10cSrcweir 	catch ( RuntimeException& e )
123*cdf0e10cSrcweir 	{
124*cdf0e10cSrcweir 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
125*cdf0e10cSrcweir 	}
126*cdf0e10cSrcweir 	catch( SAXException& e )
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir 		SAXException aWrappedSAXException;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		if ( !( e.WrappedException >>= aWrappedSAXException ))
131*cdf0e10cSrcweir 			throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
132*cdf0e10cSrcweir 		else
133*cdf0e10cSrcweir 			throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() );
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 	catch( ::com::sun::star::io::IOException& e )
136*cdf0e10cSrcweir 	{
137*cdf0e10cSrcweir 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
138*cdf0e10cSrcweir 	}
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir PopupMenu* MenuConfiguration::CreateBookmarkMenu(
142*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
143*cdf0e10cSrcweir 	const ::rtl::OUString& aURL )
144*cdf0e10cSrcweir throw ( ::com::sun::star::lang::WrappedTargetException )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	if ( aURL == BOOKMARK_NEWMENU )
147*cdf0e10cSrcweir 		return new BmkMenu( rFrame, BmkMenu::BMK_NEWMENU );
148*cdf0e10cSrcweir 	else if ( aURL == BOOKMARK_WIZARDMENU )
149*cdf0e10cSrcweir 		return new BmkMenu( rFrame, BmkMenu::BMK_WIZARDMENU );
150*cdf0e10cSrcweir 	else
151*cdf0e10cSrcweir 		return NULL;
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir void MenuConfiguration::StoreMenuBarConfigurationToXML(
155*cdf0e10cSrcweir     Reference< XIndexAccess >& rMenuBarConfiguration,
156*cdf0e10cSrcweir     Reference< XOutputStream >& rOutputStream )
157*cdf0e10cSrcweir throw ( WrappedTargetException )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	Reference< XDocumentHandler > xWriter;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	xWriter = Reference< XDocumentHandler >( m_rxServiceManager->createInstance(
162*cdf0e10cSrcweir 			SERVICENAME_SAXWRITER), UNO_QUERY) ;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	Reference< XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
165*cdf0e10cSrcweir 	xDataSource->setOutputStream( rOutputStream );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	try
168*cdf0e10cSrcweir 	{
169*cdf0e10cSrcweir         OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter );
170*cdf0e10cSrcweir 		aWriteMenuDocumentHandler.WriteMenuDocument();
171*cdf0e10cSrcweir 	}
172*cdf0e10cSrcweir 	catch ( RuntimeException& e )
173*cdf0e10cSrcweir 	{
174*cdf0e10cSrcweir 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
175*cdf0e10cSrcweir 	}
176*cdf0e10cSrcweir 	catch ( SAXException& e )
177*cdf0e10cSrcweir 	{
178*cdf0e10cSrcweir 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
179*cdf0e10cSrcweir 	}
180*cdf0e10cSrcweir 	catch ( ::com::sun::star::io::IOException& e )
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188