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