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 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_framework.hxx" 31 #include <framework/statusbarconfiguration.hxx> 32 #include <xml/statusbardocumenthandler.hxx> 33 #include <xml/saxnamespacefilter.hxx> 34 #include <services.h> 35 36 //_________________________________________________________________________________________________________________ 37 // interface includes 38 //_________________________________________________________________________________________________________________ 39 #include <com/sun/star/xml/sax/XParser.hpp> 40 #include <com/sun/star/io/XActiveDataSource.hpp> 41 #include <com/sun/star/io/XInputStream.hpp> 42 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 43 44 //_________________________________________________________________________________________________________________ 45 // other includes 46 //_________________________________________________________________________________________________________________ 47 48 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 49 #include <comphelper/processfactory.hxx> 50 #endif 51 #include <unotools/streamwrap.hxx> 52 #include <tools/debug.hxx> 53 54 //_________________________________________________________________________________________________________________ 55 // namespace 56 //_________________________________________________________________________________________________________________ 57 58 using namespace ::com::sun::star::uno; 59 using namespace ::com::sun::star::xml::sax; 60 using namespace ::com::sun::star::lang; 61 using namespace ::com::sun::star::io; 62 using namespace ::com::sun::star::container; 63 64 65 namespace framework 66 { 67 68 SV_IMPL_PTRARR( StatusBarDescriptor, StatusBarItemDescriptorPtr); 69 70 static Reference< XParser > GetSaxParser( 71 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory 72 ) 73 { 74 return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY); 75 } 76 77 static Reference< XDocumentHandler > GetSaxWriter( 78 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory 79 ) 80 { 81 return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ; 82 } 83 84 sal_Bool StatusBarConfiguration::LoadStatusBar( 85 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&, 86 SvStream&, StatusBarDescriptor& ) 87 { 88 // obsolete - only support linkage of binary filters! 89 return sal_True; 90 } 91 92 sal_Bool StatusBarConfiguration::StoreStatusBar( 93 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&, 94 SvStream&, const StatusBarDescriptor& ) 95 { 96 // obsolete - only support linkage of binary filters! 97 return sal_True; 98 } 99 100 sal_Bool StatusBarConfiguration::LoadStatusBar( 101 const Reference< XMultiServiceFactory >& xServiceFactory, 102 const Reference< XInputStream >& xInputStream, 103 const Reference< XIndexContainer >& rStatusbarConfiguration ) 104 { 105 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) ); 106 107 // connect stream to input stream to the parser 108 InputSource aInputSource; 109 aInputSource.aInputStream = xInputStream; 110 111 // create namespace filter and set menudocument handler inside to support xml namespaces 112 Reference< XDocumentHandler > xDocHandler( new OReadStatusBarDocumentHandler( rStatusbarConfiguration )); 113 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler )); 114 115 // connect parser and filter 116 xParser->setDocumentHandler( xFilter ); 117 118 try 119 { 120 xParser->parseStream( aInputSource ); 121 return sal_True; 122 } 123 catch ( RuntimeException& ) 124 { 125 return sal_False; 126 } 127 catch( SAXException& ) 128 { 129 return sal_False; 130 } 131 catch( ::com::sun::star::io::IOException& ) 132 { 133 return sal_False; 134 } 135 } 136 137 sal_Bool StatusBarConfiguration::StoreStatusBar( 138 const Reference< XMultiServiceFactory >& xServiceFactory, 139 const Reference< XOutputStream >& xOutputStream, 140 const Reference< XIndexAccess >& rStatusbarConfiguration ) 141 { 142 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) ); 143 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY ); 144 xDataSource->setOutputStream( xOutputStream ); 145 146 try 147 { 148 OWriteStatusBarDocumentHandler aWriteStatusBarDocumentHandler( rStatusbarConfiguration, xWriter ); 149 aWriteStatusBarDocumentHandler.WriteStatusBarDocument(); 150 return sal_True; 151 } 152 catch ( RuntimeException& ) 153 { 154 return sal_False; 155 } 156 catch ( SAXException& ) 157 { 158 return sal_False; 159 } 160 catch ( ::com::sun::star::io::IOException& ) 161 { 162 return sal_False; 163 } 164 } 165 } 166 167