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 65 sal_Bool MenuConfiguration::IsPickListItemId( sal_uInt16 nId ) 66 { 67 return (( START_ITEMID_PICKLIST <= nId ) && ( nId <= END_ITEMID_PICKLIST )); 68 } 69 70 sal_Bool MenuConfiguration::IsWindowListItemId( sal_uInt16 nId ) 71 { 72 return (( START_ITEMID_WINDOWLIST <= nId ) && ( nId <= END_ITEMID_WINDOWLIST )); 73 } 74 75 76 MenuConfiguration::MenuConfiguration( 77 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager ) 78 : m_rxServiceManager( rServiceManager ) 79 { 80 } 81 82 83 MenuConfiguration::~MenuConfiguration() 84 { 85 } 86 87 88 Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML( 89 Reference< XInputStream >& rInputStream ) 90 { 91 Reference< XParser > xParser( m_rxServiceManager->createInstance(SERVICENAME_SAXPARSER),UNO_QUERY); 92 93 // connect stream to input stream to the parser 94 InputSource aInputSource; 95 96 aInputSource.aInputStream = rInputStream; 97 98 99 // create menu bar 100 Reference< XIndexContainer > xItemContainer( static_cast< cppu::OWeakObject *>( new RootItemContainer()), UNO_QUERY ); 101 102 // create namespace filter and set menudocument handler inside to support xml namespaces 103 104 // #110897# Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer )); 105 Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( m_rxServiceManager, xItemContainer )); 106 107 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler )); 108 109 // connect parser and filter 110 xParser->setDocumentHandler( xFilter ); 111 112 try 113 { 114 xParser->parseStream( aInputSource ); 115 return Reference< XIndexAccess >( xItemContainer, UNO_QUERY ); 116 } 117 catch ( RuntimeException& e ) 118 { 119 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 120 } 121 catch( SAXException& e ) 122 { 123 SAXException aWrappedSAXException; 124 125 if ( !( e.WrappedException >>= aWrappedSAXException )) 126 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 127 else 128 throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() ); 129 } 130 catch( ::com::sun::star::io::IOException& e ) 131 { 132 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 133 } 134 } 135 136 PopupMenu* MenuConfiguration::CreateBookmarkMenu( 137 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 138 const ::rtl::OUString& aURL ) 139 { 140 if ( aURL == BOOKMARK_NEWMENU ) 141 return new BmkMenu( rFrame, BmkMenu::BMK_NEWMENU ); 142 else if ( aURL == BOOKMARK_WIZARDMENU ) 143 return new BmkMenu( rFrame, BmkMenu::BMK_WIZARDMENU ); 144 else 145 return NULL; 146 } 147 148 void MenuConfiguration::StoreMenuBarConfigurationToXML( 149 Reference< XIndexAccess >& rMenuBarConfiguration, 150 Reference< XOutputStream >& rOutputStream ) 151 { 152 Reference< XDocumentHandler > xWriter; 153 154 xWriter = Reference< XDocumentHandler >( m_rxServiceManager->createInstance( 155 SERVICENAME_SAXWRITER), UNO_QUERY) ; 156 157 Reference< XActiveDataSource> xDataSource( xWriter , UNO_QUERY ); 158 xDataSource->setOutputStream( rOutputStream ); 159 160 try 161 { 162 OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter ); 163 aWriteMenuDocumentHandler.WriteMenuDocument(); 164 } 165 catch ( RuntimeException& e ) 166 { 167 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 168 } 169 catch ( SAXException& e ) 170 { 171 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 172 } 173 catch ( ::com::sun::star::io::IOException& e ) 174 { 175 throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); 176 } 177 } 178 179 } 180