/src/libreoffice/framework/source/fwe/xml/toolboxconfiguration.cxx
Line | Count | Source |
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 | | #include <toolboxconfiguration.hxx> |
21 | | #include <xml/toolboxdocumenthandler.hxx> |
22 | | #include <xml/saxnamespacefilter.hxx> |
23 | | |
24 | | #include <com/sun/star/xml/sax/Parser.hpp> |
25 | | #include <com/sun/star/xml/sax/Writer.hpp> |
26 | | #include <com/sun/star/xml/sax/SAXException.hpp> |
27 | | #include <com/sun/star/io/IOException.hpp> |
28 | | #include <com/sun/star/io/XInputStream.hpp> |
29 | | |
30 | | using namespace ::com::sun::star::uno; |
31 | | using namespace ::com::sun::star::xml::sax; |
32 | | using namespace ::com::sun::star::io; |
33 | | using namespace ::com::sun::star::container; |
34 | | |
35 | | namespace framework |
36 | | { |
37 | | bool ToolBoxConfiguration::LoadToolBox( |
38 | | const css::uno::Reference<css::uno::XComponentContext>& rxContext, |
39 | | const css::uno::Reference<css::io::XInputStream>& rInputStream, |
40 | | const css::uno::Reference<css::container::XIndexContainer>& rToolbarConfiguration) |
41 | 0 | { |
42 | 0 | Reference<XParser> xParser = Parser::create(rxContext); |
43 | | |
44 | | // connect stream to input stream to the parser |
45 | 0 | InputSource aInputSource; |
46 | |
|
47 | 0 | aInputSource.aInputStream = rInputStream; |
48 | | |
49 | | // create namespace filter and set menudocument handler inside to support xml namespaces |
50 | 0 | Reference<XDocumentHandler> xDocHandler(new OReadToolBoxDocumentHandler(rToolbarConfiguration)); |
51 | 0 | Reference<XDocumentHandler> xFilter(new SaxNamespaceFilter(xDocHandler)); |
52 | | |
53 | | // connect parser and filter |
54 | 0 | xParser->setDocumentHandler(xFilter); |
55 | |
|
56 | 0 | try |
57 | 0 | { |
58 | 0 | xParser->parseStream(aInputSource); |
59 | 0 | return true; |
60 | 0 | } |
61 | 0 | catch (const RuntimeException&) |
62 | 0 | { |
63 | 0 | return false; |
64 | 0 | } |
65 | 0 | catch (const SAXException&) |
66 | 0 | { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | catch (const css::io::IOException&) |
70 | 0 | { |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | } |
74 | | |
75 | | bool ToolBoxConfiguration::StoreToolBox( |
76 | | const css::uno::Reference<css::uno::XComponentContext>& rxContext, |
77 | | const css::uno::Reference<css::io::XOutputStream>& rOutputStream, |
78 | | const css::uno::Reference<css::container::XIndexAccess>& rToolbarConfiguration) |
79 | 0 | { |
80 | 0 | Reference<XWriter> xWriter = Writer::create(rxContext); |
81 | 0 | xWriter->setOutputStream(rOutputStream); |
82 | |
|
83 | 0 | try |
84 | 0 | { |
85 | 0 | Reference<XDocumentHandler> xHandler(xWriter, UNO_QUERY_THROW); |
86 | 0 | OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler(rToolbarConfiguration, xHandler); |
87 | 0 | aWriteToolBoxDocumentHandler.WriteToolBoxDocument(); |
88 | 0 | return true; |
89 | 0 | } |
90 | 0 | catch (const RuntimeException&) |
91 | 0 | { |
92 | 0 | return false; |
93 | 0 | } |
94 | 0 | catch (const SAXException&) |
95 | 0 | { |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | catch (const css::io::IOException&) |
99 | 0 | { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | } |
103 | | } |
104 | | |
105 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |