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 <framework/toolboxconfiguration.hxx>
31 : : #include <xml/toolboxdocumenthandler.hxx>
32 : : #include <xml/saxnamespacefilter.hxx>
33 : : #include <services.h>
34 : :
35 : : #include <com/sun/star/xml/sax/XParser.hpp>
36 : : #include <com/sun/star/io/XActiveDataSource.hpp>
37 : : #include <com/sun/star/io/XInputStream.hpp>
38 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : :
40 : : #include <comphelper/processfactory.hxx>
41 : : #include <unotools/streamwrap.hxx>
42 : :
43 : : using namespace ::com::sun::star::uno;
44 : : using namespace ::com::sun::star::xml::sax;
45 : : using namespace ::com::sun::star::lang;
46 : : using namespace ::com::sun::star::io;
47 : : using namespace ::com::sun::star::container;
48 : :
49 : :
50 : : namespace framework
51 : : {
52 : :
53 : 226 : static Reference< XParser > GetSaxParser(
54 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
55 : : )
56 : : {
57 [ + - ][ + - ]: 226 : 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 : 226 : sal_Bool ToolBoxConfiguration::LoadToolBox(
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 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rToolbarConfiguration )
71 : : {
72 [ + - ]: 226 : Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
73 : :
74 : : // connect stream to input stream to the parser
75 [ + - ]: 226 : InputSource aInputSource;
76 : :
77 [ + - ]: 226 : aInputSource.aInputStream = rInputStream;
78 : :
79 : : // create namespace filter and set menudocument handler inside to support xml namespaces
80 [ + - ][ + - ]: 226 : Reference< XDocumentHandler > xDocHandler( new OReadToolBoxDocumentHandler( rToolbarConfiguration ));
[ + - ]
81 [ + - ][ + - ]: 226 : Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
[ + - # #
# # ]
82 : :
83 : : // connect parser and filter
84 [ + - ][ + - ]: 226 : xParser->setDocumentHandler( xFilter );
85 : :
86 : : try
87 : : {
88 [ + - ][ + - ]: 226 : xParser->parseStream( aInputSource );
89 : 226 : 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 [ + - ]: 226 : }
103 : : }
104 : :
105 : :
106 : 0 : sal_Bool ToolBoxConfiguration::StoreToolBox(
107 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
108 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
109 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolbarConfiguration )
110 : : {
111 [ # # ]: 0 : Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
112 : :
113 [ # # ]: 0 : Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
114 [ # # ][ # # ]: 0 : xDataSource->setOutputStream( rOutputStream );
115 : :
116 : : try
117 : : {
118 [ # # ]: 0 : OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler( rToolbarConfiguration, xWriter );
119 [ # # ]: 0 : aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
120 [ # # ]: 0 : return sal_True;
[ # # # # ]
121 : : }
122 [ # # ]: 0 : catch ( const RuntimeException& )
123 : : {
124 : 0 : return sal_False;
125 : : }
126 [ # # ]: 0 : catch ( const SAXException& )
127 : : {
128 : 0 : return sal_False;
129 : : }
130 [ # # ]: 0 : catch ( const ::com::sun::star::io::IOException& )
131 : : {
132 : 0 : return sal_False;
133 : 0 : }
134 : : }
135 : :
136 : : }
137 : :
138 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|