LibreOffice Module framework (master) 1
imagesconfiguration.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
21
24
25#include <com/sun/star/xml/sax/Parser.hpp>
26#include <com/sun/star/xml/sax/Writer.hpp>
27#include <com/sun/star/xml/sax/SAXException.hpp>
28#include <com/sun/star/io/IOException.hpp>
29#include <com/sun/star/io/XInputStream.hpp>
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::xml::sax;
33using namespace ::com::sun::star::lang;
34using namespace ::com::sun::star::io;
35
36namespace framework
37{
39 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
40 const css::uno::Reference<css::io::XInputStream>& rInputStream, ImageItemDescriptorList& rItems)
41{
42 Reference<XParser> xParser = Parser::create(rxContext);
43
44 // connect stream to input stream to the parser
45 InputSource aInputSource;
46
47 aInputSource.aInputStream = rInputStream;
48
49 // create namespace filter and set document handler inside to support xml namespaces
50 Reference<XDocumentHandler> xDocHandler(new OReadImagesDocumentHandler(rItems));
51 Reference<XDocumentHandler> xFilter(new SaxNamespaceFilter(xDocHandler));
52
53 // connect parser and filter
54 xParser->setDocumentHandler(xFilter);
55
56 try
57 {
58 xParser->parseStream(aInputSource);
59 return true;
60 }
61 catch (const RuntimeException&)
62 {
63 return false;
64 }
65 catch (const SAXException&)
66 {
67 return false;
68 }
69 catch (const css::io::IOException&)
70 {
71 return false;
72 }
73}
74
76 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
77 const css::uno::Reference<css::io::XOutputStream>& rOutputStream,
78 const ImageItemDescriptorList& rItems)
79{
80 Reference<XWriter> xWriter = Writer::create(rxContext);
81 xWriter->setOutputStream(rOutputStream);
82
83 try
84 {
85 OWriteImagesDocumentHandler aWriteImagesDocumentHandler(rItems, xWriter);
86 aWriteImagesDocumentHandler.WriteImagesDocument();
87 return true;
88 }
89 catch (const RuntimeException&)
90 {
91 return false;
92 }
93 catch (const SAXException&)
94 {
95 return false;
96 }
97 catch (const css::io::IOException&)
98 {
99 return false;
100 }
101}
102}
103
104/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool LoadImages(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XInputStream > &rInputStream, ImageItemDescriptorList &rItems)
static bool StoreImages(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XOutputStream > &rOutputStream, const ImageItemDescriptorList &rItems)
Reference< XInputStream > rInputStream
std::vector< ImageItemDescriptor > ImageItemDescriptorList