Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <framework/statusbarconfiguration.hxx>
22 : #include <xml/statusbardocumenthandler.hxx>
23 : #include <xml/saxnamespacefilter.hxx>
24 : #include <services.h>
25 :
26 : #include <com/sun/star/xml/sax/Parser.hpp>
27 : #include <com/sun/star/xml/sax/Writer.hpp>
28 : #include <com/sun/star/io/XActiveDataSource.hpp>
29 : #include <com/sun/star/io/XInputStream.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 :
32 : #include <comphelper/processfactory.hxx>
33 : #include <unotools/streamwrap.hxx>
34 :
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;
40 :
41 :
42 : namespace framework
43 : {
44 :
45 0 : sal_Bool StatusBarConfiguration::LoadStatusBar(
46 : const Reference< XComponentContext >& rxContext,
47 : const Reference< XInputStream >& xInputStream,
48 : const Reference< XIndexContainer >& rStatusbarConfiguration )
49 : {
50 0 : Reference< XParser > xParser = Parser::create(rxContext);
51 :
52 : // connect stream to input stream to the parser
53 0 : InputSource aInputSource;
54 0 : aInputSource.aInputStream = xInputStream;
55 :
56 : // create namespace filter and set menudocument handler inside to support xml namespaces
57 0 : Reference< XDocumentHandler > xDocHandler( new OReadStatusBarDocumentHandler( rStatusbarConfiguration ));
58 0 : Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
59 :
60 : // connect parser and filter
61 0 : xParser->setDocumentHandler( xFilter );
62 :
63 : try
64 : {
65 0 : xParser->parseStream( aInputSource );
66 0 : return sal_True;
67 : }
68 0 : catch ( const RuntimeException& )
69 : {
70 0 : return sal_False;
71 : }
72 0 : catch( const SAXException& )
73 : {
74 0 : return sal_False;
75 : }
76 0 : catch( const ::com::sun::star::io::IOException& )
77 : {
78 0 : return sal_False;
79 0 : }
80 : }
81 :
82 0 : sal_Bool StatusBarConfiguration::StoreStatusBar(
83 : const Reference< XComponentContext >& rxContext,
84 : const Reference< XOutputStream >& xOutputStream,
85 : const Reference< XIndexAccess >& rStatusbarConfiguration )
86 : {
87 0 : Reference< XWriter > xWriter = Writer::create( rxContext );
88 0 : xWriter->setOutputStream( xOutputStream );
89 :
90 : try
91 : {
92 0 : Reference< XDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW);
93 0 : OWriteStatusBarDocumentHandler aWriteStatusBarDocumentHandler( rStatusbarConfiguration, xHandler );
94 0 : aWriteStatusBarDocumentHandler.WriteStatusBarDocument();
95 0 : return sal_True;
96 : }
97 0 : catch ( const RuntimeException& )
98 : {
99 0 : return sal_False;
100 : }
101 0 : catch ( const SAXException& )
102 : {
103 0 : return sal_False;
104 : }
105 0 : catch ( const ::com::sun::star::io::IOException& )
106 : {
107 0 : return sal_False;
108 0 : }
109 : }
110 : }
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|