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/toolboxconfiguration.hxx>
22 : #include <xml/toolboxdocumenthandler.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 ToolBoxConfiguration::LoadToolBox(
46 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
47 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
48 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rToolbarConfiguration )
49 : {
50 0 : Reference< XParser > xParser = Parser::create(rxContext);
51 :
52 : // connect stream to input stream to the parser
53 0 : InputSource aInputSource;
54 :
55 0 : aInputSource.aInputStream = rInputStream;
56 :
57 : // create namespace filter and set menudocument handler inside to support xml namespaces
58 0 : Reference< XDocumentHandler > xDocHandler( new OReadToolBoxDocumentHandler( rToolbarConfiguration ));
59 0 : Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
60 :
61 : // connect parser and filter
62 0 : xParser->setDocumentHandler( xFilter );
63 :
64 : try
65 : {
66 0 : xParser->parseStream( aInputSource );
67 0 : return sal_True;
68 : }
69 0 : catch ( const RuntimeException& )
70 : {
71 0 : return sal_False;
72 : }
73 0 : catch( const SAXException& )
74 : {
75 0 : return sal_False;
76 : }
77 0 : catch( const ::com::sun::star::io::IOException& )
78 : {
79 0 : return sal_False;
80 0 : }
81 : }
82 :
83 :
84 0 : sal_Bool ToolBoxConfiguration::StoreToolBox(
85 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
86 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
87 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolbarConfiguration )
88 : {
89 0 : Reference< XWriter > xWriter = Writer::create(rxContext);
90 0 : xWriter->setOutputStream( rOutputStream );
91 :
92 : try
93 : {
94 0 : Reference< XDocumentHandler > xHandler( xWriter, UNO_QUERY_THROW );
95 0 : OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler( rToolbarConfiguration, xHandler );
96 0 : aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
97 0 : return sal_True;
98 : }
99 0 : catch ( const RuntimeException& )
100 : {
101 0 : return sal_False;
102 : }
103 0 : catch ( const SAXException& )
104 : {
105 0 : return sal_False;
106 : }
107 0 : catch ( const ::com::sun::star::io::IOException& )
108 : {
109 0 : return sal_False;
110 0 : }
111 : }
112 :
113 : }
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|