1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_package.hxx"
26 #include <ManifestWriter.hxx>
27 #include <ManifestExport.hxx>
28 #include <cppuhelper/factory.hxx>
29 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP
30 #include <com/sun/star/io/XActiveDataSource.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP
33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #endif
41 #ifndef _COM_SUN_STAR_XML_SAX_SAXEXCEPTION_HPP
42 #include <com/sun/star/xml/sax/SAXException.hpp>
43 #endif
44 
45 #include <osl/diagnose.hxx>
46 
47 using namespace ::rtl;
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::io;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::registry;
54 using namespace ::com::sun::star::packages;
55 using namespace ::com::sun::star::xml::sax;
56 using namespace ::com::sun::star::packages::manifest;
57 
ManifestWriter(const Reference<XMultiServiceFactory> & xNewFactory)58 ManifestWriter::ManifestWriter( const Reference < XMultiServiceFactory > & xNewFactory )
59 : xFactory ( xNewFactory )
60 {
61 }
~ManifestWriter()62 ManifestWriter::~ManifestWriter()
63 {
64 }
65 
66 // XManifestWriter methods
writeManifestSequence(const Reference<XOutputStream> & rStream,const Sequence<Sequence<PropertyValue>> & rSequence)67 void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStream >& rStream, const Sequence< Sequence< PropertyValue > >& rSequence )
68 		throw (RuntimeException)
69 {
70 	OUString sSaxWriter ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Writer" ) );
71 	Reference < XActiveDataSource > xSource ( xFactory->createInstance ( sSaxWriter ), UNO_QUERY );
72 	if (xSource.is())
73 	{
74 		xSource->setOutputStream ( rStream );
75 		Reference < XDocumentHandler > xHandler ( xSource, UNO_QUERY );
76 		if (xHandler.is())
77 			try {
78 				ManifestExport aExporter ( xHandler, rSequence);
79 			}
80 			catch( SAXException& )
81 			{
82 				throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
83 			}
84 	}
85 }
86 
87 // Component methods
ManifestWriter_createInstance(Reference<XMultiServiceFactory> const & rServiceFactory)88 Reference < XInterface > SAL_CALL ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
89 {
90 	return *new ManifestWriter( rServiceFactory );
91 }
92 
static_getImplementationName()93 OUString ManifestWriter::static_getImplementationName()
94 {
95 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestWriter" ) );
96 }
97 
static_supportsService(OUString const & rServiceName)98 sal_Bool SAL_CALL ManifestWriter::static_supportsService(OUString const & rServiceName)
99 {
100 	return rServiceName == getSupportedServiceNames()[0];
101 }
static_getSupportedServiceNames()102 Sequence < OUString > ManifestWriter::static_getSupportedServiceNames()
103 {
104 	Sequence < OUString > aNames(1);
105 	aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) );
106 	return aNames;
107 }
108 
getImplementationName()109 OUString ManifestWriter::getImplementationName()
110 	throw (RuntimeException)
111 {
112 	return static_getImplementationName();
113 }
114 
supportsService(OUString const & rServiceName)115 sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName)
116 	throw (RuntimeException)
117 {
118 	return static_supportsService ( rServiceName );
119 }
getSupportedServiceNames()120 Sequence < OUString > ManifestWriter::getSupportedServiceNames()
121 	throw (RuntimeException)
122 {
123 	return static_getSupportedServiceNames();
124 }
createServiceFactory(Reference<XMultiServiceFactory> const & rServiceFactory)125 Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
126 {
127 	return cppu::createSingleFactory (rServiceFactory,
128 										   static_getImplementationName(),
129 										   ManifestWriter_createInstance,
130 										   static_getSupportedServiceNames());
131 }
132