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