Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <xml/imagesconfiguration.hxx>
31 : : #include <services.h>
32 : :
33 : : #include <xml/imagesdocumenthandler.hxx>
34 : : #include <xml/saxnamespacefilter.hxx>
35 : :
36 : : #include <com/sun/star/xml/sax/XParser.hpp>
37 : : #include <com/sun/star/io/XActiveDataSource.hpp>
38 : : #include <com/sun/star/io/XInputStream.hpp>
39 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 : :
41 : : #include <comphelper/processfactory.hxx>
42 : : #include <unotools/streamwrap.hxx>
43 : :
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::com::sun::star::xml::sax;
46 : : using namespace ::com::sun::star::lang;
47 : : using namespace ::com::sun::star::io;
48 : :
49 : :
50 : : namespace framework
51 : : {
52 : :
53 : 0 : static Reference< XParser > GetSaxParser(
54 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
55 : : )
56 : : {
57 [ # # ][ # # ]: 0 : return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
58 : : }
59 : :
60 : 0 : static Reference< XDocumentHandler > GetSaxWriter(
61 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
62 : : )
63 : : {
64 [ # # ][ # # ]: 0 : return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
65 : : }
66 : :
67 : 0 : sal_Bool ImagesConfiguration::LoadImages(
68 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
69 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
70 : : ImageListsDescriptor& rItems )
71 : : {
72 [ # # ]: 0 : Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
73 : :
74 : : // connect stream to input stream to the parser
75 [ # # ]: 0 : InputSource aInputSource;
76 : :
77 [ # # ]: 0 : aInputSource.aInputStream = rInputStream;
78 : :
79 : : // create namespace filter and set document handler inside to support xml namespaces
80 [ # # ][ # # ]: 0 : Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( rItems ));
[ # # ]
81 [ # # ][ # # ]: 0 : Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
[ # # # #
# # ]
82 : :
83 : : // connect parser and filter
84 [ # # ][ # # ]: 0 : xParser->setDocumentHandler( xFilter );
85 : :
86 : : try
87 : : {
88 [ # # ][ # # ]: 0 : xParser->parseStream( aInputSource );
89 : 0 : return sal_True;
90 : : }
91 [ # # ]: 0 : catch ( const RuntimeException& )
92 : : {
93 : 0 : return sal_False;
94 : : }
95 [ # # ]: 0 : catch( const SAXException& )
96 : : {
97 : 0 : return sal_False;
98 : : }
99 [ # # ]: 0 : catch( const ::com::sun::star::io::IOException& )
100 : : {
101 : 0 : return sal_False;
102 [ # # ]: 0 : }
103 : : }
104 : :
105 : 0 : sal_Bool ImagesConfiguration::StoreImages(
106 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
107 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
108 : : const ImageListsDescriptor& rItems )
109 : : {
110 [ # # ]: 0 : Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
111 : :
112 [ # # ]: 0 : Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
113 [ # # ][ # # ]: 0 : xDataSource->setOutputStream( rOutputStream );
114 : :
115 : : try
116 : : {
117 [ # # ]: 0 : OWriteImagesDocumentHandler aWriteImagesDocumentHandler( rItems, xWriter );
118 [ # # ]: 0 : aWriteImagesDocumentHandler.WriteImagesDocument();
119 [ # # ]: 0 : return sal_True;
[ # # # # ]
120 : : }
121 [ # # ]: 0 : catch ( const RuntimeException& )
122 : : {
123 : 0 : return sal_False;
124 : : }
125 [ # # ]: 0 : catch ( const SAXException& )
126 : : {
127 : 0 : return sal_False;
128 : : }
129 [ # # ]: 0 : catch ( const ::com::sun::star::io::IOException& )
130 : : {
131 : 0 : return sal_False;
132 : 0 : }
133 : : }
134 : :
135 : : }
136 : :
137 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|