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