Sukapura: tdf#147664 Shrink some icons to make them balance
[LibreOffice.git] / framework / source / fwe / xml / toolboxconfiguration.cxx
blobd9e34baabc98ce3c8ad8297bb716fb662a1dfa63
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 <toolboxconfiguration.hxx>
21 #include <xml/toolboxdocumenthandler.hxx>
22 #include <xml/saxnamespacefilter.hxx>
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>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::io;
34 using namespace ::com::sun::star::container;
36 namespace framework
38 bool ToolBoxConfiguration::LoadToolBox(
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)
43 Reference<XParser> xParser = Parser::create(rxContext);
45 // connect stream to input stream to the parser
46 InputSource aInputSource;
48 aInputSource.aInputStream = rInputStream;
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));
54 // connect parser and filter
55 xParser->setDocumentHandler(xFilter);
57 try
59 xParser->parseStream(aInputSource);
60 return true;
62 catch (const RuntimeException&)
64 return false;
66 catch (const SAXException&)
68 return false;
70 catch (const css::io::IOException&)
72 return false;
76 bool ToolBoxConfiguration::StoreToolBox(
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)
81 Reference<XWriter> xWriter = Writer::create(rxContext);
82 xWriter->setOutputStream(rOutputStream);
84 try
86 Reference<XDocumentHandler> xHandler(xWriter, UNO_QUERY_THROW);
87 OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler(rToolbarConfiguration, xHandler);
88 aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
89 return true;
91 catch (const RuntimeException&)
93 return false;
95 catch (const SAXException&)
97 return false;
99 catch (const css::io::IOException&)
101 return false;
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */