nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / meta / MetaExportComponent.cxx
blob376a844e204d5f932147ae4ae9c369b4dd1286db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <MetaExportComponent.hxx>
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/uno/Exception.hpp>
25 #include <com/sun/star/util/MeasureUnit.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <comphelper/genericpropertyset.hxx>
30 #include <comphelper/propertysetinfo.hxx>
31 #include <osl/diagnose.h>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/namespacemap.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlmetae.hxx>
36 #include <PropertySetMerger.hxx>
38 #include <unotools/docinfohelper.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
44 XMLMetaExportComponent::XMLMetaExportComponent(
45 const css::uno::Reference< css::uno::XComponentContext >& xContext,
46 OUString const & implementationName, SvXMLExportFlags nFlags )
47 : SvXMLExport( xContext, implementationName, util::MeasureUnit::CM, XML_TEXT, nFlags )
51 XMLMetaExportComponent::~XMLMetaExportComponent()
55 void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
57 try
59 SvXMLExport::setSourceDocument( xDoc );
61 catch( lang::IllegalArgumentException& )
63 // allow to use document properties service without model access
64 // this is required for document properties exporter
65 mxDocProps =
66 uno::Reference< document::XDocumentProperties >::query( xDoc );
67 if( !mxDocProps.is() )
68 throw lang::IllegalArgumentException();
72 ErrCode XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
74 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
76 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
78 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
79 try
81 ::comphelper::PropertyMapEntry const aInfoMap[] =
83 { OUString("Class"), 0,
84 ::cppu::UnoType<OUString>::get(),
85 beans::PropertyAttribute::MAYBEVOID, 0},
86 { OUString(), 0, css::uno::Type(), 0, 0 }
88 uno::Reference< beans::XPropertySet > xConvPropSet(
89 ::comphelper::GenericPropertySet_CreateInstance(
90 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
92 xConvPropSet->setPropertyValue("Class", uno::Any(GetXMLToken( XML_TEXT )) );
94 uno::Reference< beans::XPropertySet > xPropSet =
95 getExportInfo().is()
96 ? PropertySetMerger_CreateInstance( getExportInfo(),
97 xConvPropSet )
98 : getExportInfo();
100 uno::Sequence< uno::Any > aArgs( 3 );
101 aArgs[0] <<= xDocHandler;
102 aArgs[1] <<= xPropSet;
103 aArgs[2] <<= GetModel();
105 // get filter component
106 xDocHandler.set(
107 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
108 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
109 uno::UNO_QUERY_THROW );
111 SetDocHandler( xDocHandler );
113 catch( css::uno::Exception& )
115 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!");
120 xDocHandler->startDocument();
122 addChaffWhenEncryptedStorage();
126 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
127 sal_uInt16 nPos = rMap.GetFirstKey();
128 while( USHRT_MAX != nPos )
130 GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
131 nPos = GetNamespaceMap().GetNextKey( nPos );
134 const char*const pVersion = GetODFVersionAttributeValue();
136 if( pVersion )
137 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
138 OUString::createFromAscii(pVersion) );
140 SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
141 true, true );
143 // NB: office:meta is now written by _ExportMeta
144 ExportMeta_();
146 xDocHandler->endDocument();
147 return ERRCODE_NONE;
150 void XMLMetaExportComponent::ExportMeta_()
152 if (mxDocProps.is()) {
153 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
154 // update generator here
155 mxDocProps->setGenerator(generator);
156 rtl::Reference<SvXMLMetaExport> pMeta = new SvXMLMetaExport(*this, mxDocProps);
157 pMeta->Export();
158 } else {
159 SvXMLExport::ExportMeta_();
163 // methods without content:
164 void XMLMetaExportComponent::ExportAutoStyles_() {}
165 void XMLMetaExportComponent::ExportMasterStyles_() {}
166 void XMLMetaExportComponent::ExportContent_() {}
168 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
169 XMLMetaExportComponent_get_implementation(
170 css::uno::XComponentContext *context,
171 css::uno::Sequence<css::uno::Any> const &)
173 return cppu::acquire(new XMLMetaExportComponent(context, "XMLMetaExportComponent", SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
176 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
177 XMLMetaExportOOo_get_implementation(css::uno::XComponentContext* context,
178 css::uno::Sequence<css::uno::Any> const&)
180 return cppu::acquire(
181 new XMLMetaExportComponent(context, "XMLMetaExportOOo", SvXMLExportFlags::META));
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */