1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_package.hxx" 30 #include <ManifestWriter.hxx> 31 #include <ManifestExport.hxx> 32 #include <cppuhelper/factory.hxx> 33 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP 34 #include <com/sun/star/io/XActiveDataSource.hpp> 35 #endif 36 #ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP 37 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 38 #endif 39 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP 40 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 41 #endif 42 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP 43 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 44 #endif 45 #ifndef _COM_SUN_STAR_XML_SAX_SAXEXCEPTION_HPP 46 #include <com/sun/star/xml/sax/SAXException.hpp> 47 #endif 48 49 #include <osl/diagnose.hxx> 50 51 using namespace ::rtl; 52 using namespace ::com::sun::star; 53 using namespace ::com::sun::star::uno; 54 using namespace ::com::sun::star::beans; 55 using namespace ::com::sun::star::io; 56 using namespace ::com::sun::star::lang; 57 using namespace ::com::sun::star::registry; 58 using namespace ::com::sun::star::packages; 59 using namespace ::com::sun::star::xml::sax; 60 using namespace ::com::sun::star::packages::manifest; 61 62 ManifestWriter::ManifestWriter( const Reference < XMultiServiceFactory > & xNewFactory ) 63 : xFactory ( xNewFactory ) 64 { 65 } 66 ManifestWriter::~ManifestWriter() 67 { 68 } 69 70 // XManifestWriter methods 71 void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStream >& rStream, const Sequence< Sequence< PropertyValue > >& rSequence ) 72 throw (RuntimeException) 73 { 74 OUString sSaxWriter ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Writer" ) ); 75 Reference < XActiveDataSource > xSource ( xFactory->createInstance ( sSaxWriter ), UNO_QUERY ); 76 if (xSource.is()) 77 { 78 xSource->setOutputStream ( rStream ); 79 Reference < XDocumentHandler > xHandler ( xSource, UNO_QUERY ); 80 if (xHandler.is()) 81 try { 82 ManifestExport aExporter ( xHandler, rSequence); 83 } 84 catch( SAXException& ) 85 { 86 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); 87 } 88 } 89 } 90 91 // Component methods 92 Reference < XInterface > SAL_CALL ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) 93 { 94 return *new ManifestWriter( rServiceFactory ); 95 } 96 97 OUString ManifestWriter::static_getImplementationName() 98 { 99 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestWriter" ) ); 100 } 101 102 sal_Bool SAL_CALL ManifestWriter::static_supportsService(OUString const & rServiceName) 103 { 104 return rServiceName == getSupportedServiceNames()[0]; 105 } 106 Sequence < OUString > ManifestWriter::static_getSupportedServiceNames() 107 { 108 Sequence < OUString > aNames(1); 109 aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) ); 110 return aNames; 111 } 112 113 OUString ManifestWriter::getImplementationName() 114 throw (RuntimeException) 115 { 116 return static_getImplementationName(); 117 } 118 119 sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName) 120 throw (RuntimeException) 121 { 122 return static_supportsService ( rServiceName ); 123 } 124 Sequence < OUString > ManifestWriter::getSupportedServiceNames() 125 throw (RuntimeException) 126 { 127 return static_getSupportedServiceNames(); 128 } 129 Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) 130 { 131 return cppu::createSingleFactory (rServiceFactory, 132 static_getImplementationName(), 133 ManifestWriter_createInstance, 134 static_getSupportedServiceNames()); 135 } 136