1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 #include <framework/menuconfiguration.hxx>
31 
32 #ifndef __FRAMEWORK_CLASSES_BMKMENU_HXX_
33 #include <framework/bmkmenu.hxx>
34 #endif
35 #include <framework/addonmenu.hxx>
36 #include <xml/menudocumenthandler.hxx>
37 #include <xml/saxnamespacefilter.hxx>
38 #include <services.h>
39 
40 #ifndef _FRAMEWORK_UIELEMENT_ROOTITEMCONTAINER_HXX_
41 #include <uielement/rootitemcontainer.hxx>
42 #endif
43 
44 //_________________________________________________________________________________________________________________
45 //	interface includes
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/xml/sax/XParser.hpp>
48 #include <com/sun/star/io/XActiveDataSource.hpp>
49 #include <com/sun/star/frame/XFrame.hpp>
50 
51 //_________________________________________________________________________________________________________________
52 //	namespace
53 //_________________________________________________________________________________________________________________
54 
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::xml::sax;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::io;
61 
62 namespace framework
63 {
64 
IsPickListItemId(sal_uInt16 nId)65 sal_Bool MenuConfiguration::IsPickListItemId( sal_uInt16 nId )
66 {
67     return (( START_ITEMID_PICKLIST <= nId ) && ( nId <= END_ITEMID_PICKLIST ));
68 }
69 
IsWindowListItemId(sal_uInt16 nId)70 sal_Bool MenuConfiguration::IsWindowListItemId( sal_uInt16 nId )
71 {
72     return (( START_ITEMID_WINDOWLIST <= nId ) && ( nId <= END_ITEMID_WINDOWLIST ));
73 }
74 
75 
MenuConfiguration(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & rServiceManager)76 MenuConfiguration::MenuConfiguration(
77 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager )
78 :	m_rxServiceManager( rServiceManager )
79 {
80 }
81 
82 
~MenuConfiguration()83 MenuConfiguration::~MenuConfiguration()
84 {
85 }
86 
87 
CreateMenuBarConfigurationFromXML(Reference<XInputStream> & rInputStream)88 Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML(
89     Reference< XInputStream >& rInputStream )
90 throw ( WrappedTargetException )
91 {
92 	Reference< XParser > xParser( m_rxServiceManager->createInstance(SERVICENAME_SAXPARSER),UNO_QUERY);
93 
94 	// connect stream to input stream to the parser
95 	InputSource aInputSource;
96 
97 	aInputSource.aInputStream = rInputStream;
98 
99 
100 	// create menu bar
101     Reference< XIndexContainer > xItemContainer( static_cast< cppu::OWeakObject *>( new RootItemContainer()), UNO_QUERY );
102 
103 	// create namespace filter and set menudocument handler inside to support xml namespaces
104 
105 	// #110897# Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
106 	Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( m_rxServiceManager, xItemContainer ));
107 
108 	Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
109 
110 	// connect parser and filter
111 	xParser->setDocumentHandler( xFilter );
112 
113 	try
114 	{
115 		xParser->parseStream( aInputSource );
116 		return Reference< XIndexAccess >( xItemContainer, UNO_QUERY );
117 	}
118 	catch ( RuntimeException& e )
119 	{
120 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
121 	}
122 	catch( SAXException& e )
123 	{
124 		SAXException aWrappedSAXException;
125 
126 		if ( !( e.WrappedException >>= aWrappedSAXException ))
127 			throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
128 		else
129 			throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() );
130 	}
131 	catch( ::com::sun::star::io::IOException& e )
132 	{
133 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
134 	}
135 }
136 
CreateBookmarkMenu(::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & rFrame,const::rtl::OUString & aURL)137 PopupMenu* MenuConfiguration::CreateBookmarkMenu(
138 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
139 	const ::rtl::OUString& aURL )
140 throw ( ::com::sun::star::lang::WrappedTargetException )
141 {
142 	if ( aURL == BOOKMARK_NEWMENU )
143 		return new BmkMenu( rFrame, BmkMenu::BMK_NEWMENU );
144 	else if ( aURL == BOOKMARK_WIZARDMENU )
145 		return new BmkMenu( rFrame, BmkMenu::BMK_WIZARDMENU );
146 	else
147 		return NULL;
148 }
149 
StoreMenuBarConfigurationToXML(Reference<XIndexAccess> & rMenuBarConfiguration,Reference<XOutputStream> & rOutputStream)150 void MenuConfiguration::StoreMenuBarConfigurationToXML(
151     Reference< XIndexAccess >& rMenuBarConfiguration,
152     Reference< XOutputStream >& rOutputStream )
153 throw ( WrappedTargetException )
154 {
155 	Reference< XDocumentHandler > xWriter;
156 
157 	xWriter = Reference< XDocumentHandler >( m_rxServiceManager->createInstance(
158 			SERVICENAME_SAXWRITER), UNO_QUERY) ;
159 
160 	Reference< XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
161 	xDataSource->setOutputStream( rOutputStream );
162 
163 	try
164 	{
165         OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter );
166 		aWriteMenuDocumentHandler.WriteMenuDocument();
167 	}
168 	catch ( RuntimeException& e )
169 	{
170 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
171 	}
172 	catch ( SAXException& e )
173 	{
174 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
175 	}
176 	catch ( ::com::sun::star::io::IOException& e )
177 	{
178 		throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
179 	}
180 }
181 
182 }
183 
184