1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menuconfiguration.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
37 #include <xml/menuconfiguration.hxx>
39 #ifndef __FRAMEWORK_CLASSES_BMKMENU_HXX_
40 #include <classes/bmkmenu.hxx>
42 #include <classes/addonmenu.hxx>
43 #include <xml/menudocumenthandler.hxx>
44 #include <xml/saxnamespacefilter.hxx>
47 #ifndef _FRAMEWORK_SERVICES_LAYOUTMANAGER_HXX_
48 #include <services/layoutmanager.hxx>
51 #ifndef _FRAMEWORK_UIELEMENT_ROOTITEMCONTAINER_HXX_
52 #include <uielement/rootitemcontainer.hxx>
55 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
58 #include <com/sun/star/xml/sax/XParser.hpp>
59 #include <com/sun/star/io/XActiveDataSource.hpp>
60 #include <com/sun/star/frame/XFrame.hpp>
62 //_________________________________________________________________________________________________________________
64 //_________________________________________________________________________________________________________________
66 using namespace ::com::sun::star::uno
;
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::beans
;
69 using namespace ::com::sun::star::xml::sax
;
70 using namespace ::com::sun::star::container
;
71 using namespace ::com::sun::star::io
;
76 BOOL
MenuConfiguration::IsPickListItemId( USHORT nId
)
78 return (( START_ITEMID_PICKLIST
<= nId
) && ( nId
<= END_ITEMID_PICKLIST
));
81 BOOL
MenuConfiguration::IsWindowListItemId( USHORT nId
)
83 return (( START_ITEMID_WINDOWLIST
<= nId
) && ( nId
<= END_ITEMID_WINDOWLIST
));
87 MenuConfiguration::MenuConfiguration(
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& rServiceManager
)
89 : m_rxServiceManager( rServiceManager
)
94 MenuConfiguration::~MenuConfiguration()
99 Reference
< XIndexAccess
> MenuConfiguration::CreateMenuBarConfigurationFromXML(
100 Reference
< XInputStream
>& rInputStream
)
101 throw ( WrappedTargetException
)
103 Reference
< XParser
> xParser( m_rxServiceManager
->createInstance(SERVICENAME_SAXPARSER
),UNO_QUERY
);
105 // connect stream to input stream to the parser
106 InputSource aInputSource
;
108 aInputSource
.aInputStream
= rInputStream
;
112 Reference
< XIndexContainer
> xItemContainer( static_cast< cppu::OWeakObject
*>( new RootItemContainer()), UNO_QUERY
);
114 // create namespace filter and set menudocument handler inside to support xml namespaces
116 // #110897# Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
117 Reference
< XDocumentHandler
> xDocHandler( new OReadMenuDocumentHandler( m_rxServiceManager
, xItemContainer
));
119 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
121 // connect parser and filter
122 xParser
->setDocumentHandler( xFilter
);
126 xParser
->parseStream( aInputSource
);
127 return Reference
< XIndexAccess
>( xItemContainer
, UNO_QUERY
);
129 catch ( RuntimeException
& e
)
131 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
133 catch( SAXException
& e
)
135 SAXException aWrappedSAXException
;
137 if ( !( e
.WrappedException
>>= aWrappedSAXException
))
138 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
140 throw WrappedTargetException( aWrappedSAXException
.Message
, Reference
< XInterface
>(), Any() );
142 catch( ::com::sun::star::io::IOException
& e
)
144 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
148 PopupMenu
* MenuConfiguration::CreateBookmarkMenu(
149 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
150 const ::rtl::OUString
& aURL
)
151 throw ( ::com::sun::star::lang::WrappedTargetException
)
153 if ( aURL
== BOOKMARK_NEWMENU
)
154 return new BmkMenu( rFrame
, BmkMenu::BMK_NEWMENU
);
155 else if ( aURL
== BOOKMARK_WIZARDMENU
)
156 return new BmkMenu( rFrame
, BmkMenu::BMK_WIZARDMENU
);
161 void MenuConfiguration::StoreMenuBarConfigurationToXML(
162 Reference
< XIndexAccess
>& rMenuBarConfiguration
,
163 Reference
< XOutputStream
>& rOutputStream
)
164 throw ( WrappedTargetException
)
166 Reference
< XDocumentHandler
> xWriter
;
168 xWriter
= Reference
< XDocumentHandler
>( m_rxServiceManager
->createInstance(
169 SERVICENAME_SAXWRITER
), UNO_QUERY
) ;
171 Reference
< XActiveDataSource
> xDataSource( xWriter
, UNO_QUERY
);
172 xDataSource
->setOutputStream( rOutputStream
);
176 OWriteMenuDocumentHandler
aWriteMenuDocumentHandler( rMenuBarConfiguration
, xWriter
);
177 aWriteMenuDocumentHandler
.WriteMenuDocument();
179 catch ( RuntimeException
& e
)
181 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
183 catch ( SAXException
& e
)
185 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
187 catch ( ::com::sun::star::io::IOException
& e
)
189 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );