Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / fwe / xml / statusbarconfiguration.cxx
blob732af0e60e359f43e5f5fcdbcdd8aac31ff729ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <framework/statusbarconfiguration.hxx>
21 #include <xml/statusbardocumenthandler.hxx>
22 #include <xml/saxnamespacefilter.hxx>
23 #include <services.h>
25 #include <com/sun/star/xml/sax/Parser.hpp>
26 #include <com/sun/star/xml/sax/Writer.hpp>
27 #include <com/sun/star/xml/sax/SAXException.hpp>
28 #include <com/sun/star/io/IOException.hpp>
29 #include <com/sun/star/io/XActiveDataSource.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <unotools/streamwrap.hxx>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::io;
39 using namespace ::com::sun::star::container;
41 namespace framework
44 bool StatusBarConfiguration::LoadStatusBar(
45 const Reference< XComponentContext >& rxContext,
46 const Reference< XInputStream >& xInputStream,
47 const Reference< XIndexContainer >& rStatusbarConfiguration )
49 Reference< XParser > xParser = Parser::create(rxContext);
51 // connect stream to input stream to the parser
52 InputSource aInputSource;
53 aInputSource.aInputStream = xInputStream;
55 // create namespace filter and set menudocument handler inside to support xml namespaces
56 Reference< XDocumentHandler > xDocHandler( new OReadStatusBarDocumentHandler( rStatusbarConfiguration ));
57 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
59 // connect parser and filter
60 xParser->setDocumentHandler( xFilter );
62 try
64 xParser->parseStream( aInputSource );
65 return true;
67 catch ( const RuntimeException& )
69 return false;
71 catch( const SAXException& )
73 return false;
75 catch( const css::io::IOException& )
77 return false;
81 bool StatusBarConfiguration::StoreStatusBar(
82 const Reference< XComponentContext >& rxContext,
83 const Reference< XOutputStream >& xOutputStream,
84 const Reference< XIndexAccess >& rStatusbarConfiguration )
86 Reference< XWriter > xWriter = Writer::create( rxContext );
87 xWriter->setOutputStream( xOutputStream );
89 try
91 OWriteStatusBarDocumentHandler aWriteStatusBarDocumentHandler( rStatusbarConfiguration, xWriter );
92 aWriteStatusBarDocumentHandler.WriteStatusBarDocument();
93 return true;
95 catch ( const RuntimeException& )
97 return false;
99 catch ( const SAXException& )
101 return false;
103 catch ( const css::io::IOException& )
105 return false;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */