1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <xml/imagesconfiguration.hxx>
23 #include <xml/imagesdocumenthandler.hxx>
24 #include <xml/saxnamespacefilter.hxx>
26 #include <com/sun/star/xml/sax/Parser.hpp>
27 #include <com/sun/star/xml/sax/Writer.hpp>
28 #include <com/sun/star/xml/sax/SAXException.hpp>
29 #include <com/sun/star/io/IOException.hpp>
30 #include <com/sun/star/io/XActiveDataSource.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <unotools/streamwrap.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::xml::sax
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::io
;
44 bool ImagesConfiguration::LoadImages(
45 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
46 const css::uno::Reference
< css::io::XInputStream
>& rInputStream
,
47 ImageItemDescriptorList
& rItems
)
49 Reference
< XParser
> xParser
= Parser::create( rxContext
);
51 // connect stream to input stream to the parser
52 InputSource aInputSource
;
54 aInputSource
.aInputStream
= rInputStream
;
56 // create namespace filter and set document handler inside to support xml namespaces
57 Reference
< XDocumentHandler
> xDocHandler( new OReadImagesDocumentHandler( rItems
));
58 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
60 // connect parser and filter
61 xParser
->setDocumentHandler( xFilter
);
65 xParser
->parseStream( aInputSource
);
68 catch ( const RuntimeException
& )
72 catch( const SAXException
& )
76 catch( const css::io::IOException
& )
82 bool ImagesConfiguration::StoreImages(
83 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
84 const css::uno::Reference
< css::io::XOutputStream
>& rOutputStream
,
85 const ImageItemDescriptorList
& rItems
)
87 Reference
< XWriter
> xWriter
= Writer::create(rxContext
);
88 xWriter
->setOutputStream( rOutputStream
);
92 OWriteImagesDocumentHandler
aWriteImagesDocumentHandler( rItems
, xWriter
);
93 aWriteImagesDocumentHandler
.WriteImagesDocument();
96 catch ( const RuntimeException
& )
100 catch ( const SAXException
& )
104 catch ( const css::io::IOException
& )
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */