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