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