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